Android 让EditText不自动获取焦点

进入一个页面后,EditText会自动获取焦点并且弹出软键盘,有时候并不需要自动弹出,要解决此问题,需要在布局文件中,EditText的父级控件中修改:

android:focusable="true" 
android:focusableInTouchMode="true"

这样会在EditText父级控件中拦截EditText自动获取焦点的行为

代码如下:

<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"
    android:focusable="true" android:focusableInTouchMode="true">

  <TextView android:layout_width="0dp" android:layout_height="wrap_content"
      android:layout_weight="3" android:gravity="right"
      android:text="手机号码:"/>

  <EditText android:layout_width="0dp" android:layout_height="wrap_content"
      android:layout_weight="7" android:hint="注册时使用的手机号码"/>

</LinearLayout>

猜你喜欢

转载自blog.csdn.net/weihua_li/article/details/72954077