Android设置默认取消获得焦点或显示软键盘
Android在比较大的页面有时候有EditText在页面下方,程序默认会跳转到第一个EditText的位置并弹出软键盘,如果我们需要从头看起,就要做一些设置。
一.不弹出软键盘的设置
有下面几种方法:
(一) 在 父 Activity 中 onCreate 中加上
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
(二)在 AndroidMainfest.xml中选择哪个activity,设置windowSoftInputMode属性为 adjustUnspecified|stateHidden
< activity Android:name=".Main"
android:label="@string/app_name"
android:windowSoftInputMode="adjustUnspecified|stateHidden"
android:configChanges="orientation|keyboardHidden">
。。。
</activity>
二.EdiText默认不获得焦点的设置
有时候调用EditText调用 clearFouse()方法不一定有用!
解决之道:在EditText的父级控件中找一个,设置成
android:focusable="true"
android:focusableInTouchMode="true"
这样,就把EditText默认的行为截断了!
比如:
<LinearLayout
style="@style/FillWrapWidgetStyle"
android:orientation="vertical"
android:background="@color/black"
android:gravity="center_horizontal"
android:focusable="true"
android:focusableInTouchMode="true"
>
<ImageView
android:id="@+id/logo"
style="@style/WrapContentWidgetStyle"
android:background="@drawable/dream_dictionary_logo"
/>
<RelativeLayout
style="@style/FillWrapWidgetStyle"
android:background="@drawable/searchbar_bg"
android:gravity="center_vertical"
>
<EditText
android:id="@+id/searchEditText"
style="@style/WrapContentWidgetStyle"
android:background="@null"
android:hint="Search"
android:layout_marginLeft="40dp"
android:singleLine="true"
/>
</RelativeLayout>
</LinearLayout>
共勉:让自己越来越强大。