EditText focus control, edittext focus
1. by default, EditText gets the focus, which in some cases hinders the functions implemented by developers, such as the Development search function. After EditText is added, the page is displayed by default, editText also gets the focus, but the user does not have the search function in the actual application. To achieve EditText, the focus is lost by default. The method is as follows:
Add in the EditText parent container
Android: focusable = "true"
Android: focusableInTouchMode = "true"
You can. For example:
<FrameLayout
Android: layout_width = "match_parent"
Android: layout_height = "@ dimen/fragment_look_list_et_layout_height"
Android: layout_marginTop = "1dip"
Android: background = "# f0f0f0"
Android: focusable = "true"
Android: focusableInTouchMode = "true"
Android: gravity = "center"
Android: paddingLeft = "@ dimen/fragment_look_list_et_padding"
Android: paddingRight = "@ dimen/fragment_look_list_et_padding">
<EditText
Android: id = "@ + id/et_search"
Android: layout_width = "match_parent"
Android: layout_height = "@ dimen/fragment_look_list_et_height_width"
Android: layout_gravity = "center"
Android: singleLine = "true"
Android: ellipsize = "start"
Android: background = "@ drawable/shape_look_list_et_bg"
Android: gravity = "center_vertical"
Android: textSize = "14sp"
Android: paddingRight = "@ dimen/fragment_look_list_et_padding_right"
Android: paddingLeft = "@ dimen/fragment_look_list_et_padding_left"/>
</FrameLayout>
2. after solving the problem of focus in the default situation, we usually want to use code to dynamically control the loss of focus (it's easy to get the focus, just click it ), for example, there is a ListVIew list under the search box. When we slide the list, we hope that EditText will lose the focus, as follows:
(1) first, add android: windowSoftInputMode = "stateHidden | adjustResize" to the AndroidManiFest. xml activity"
For example:
<Activity
Android: name = ". activity. MainActivity"
Android: label = "@ string/app_name"
Android: windowSoftInputMode = "stateHidden | adjustResize"
Android: screenOrientation = "portrait">
<Intent-filter>
<Action android: name = "android. intent. action. MAIN"/>
<Category android: name = "android. intent. category. LAUNCHER"/>
</Intent-filter>
</Activity>
(2) EditText loses focus code:
// EditText loses focus
SearchET. clearFocus ();