进入一个页面后,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>