Editext自动获取焦点问题
在项目布局中,如果界面上有editext控件,那么就会自动弹出输入法软键盘,原因在editext自动获取了了焦点,进行弹出了软键盘,解决方法有两个如下所示:
一:
在EditText的父级控件中找一个,设置成
Android:focusable="true"
android:focusableInTouchMode="true"
这样,就把EditText默认的行为截断了!如下所示:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/eb" android:focusable="true" android:focusableInTouchMode="true"> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" /> </RelativeLayout>
二:调用关闭软键盘和editext的clearFocus();
EditText对象的clearFocus();
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(editMsgView.getWindowToken(), 0);(关闭软键盘。。。)