Original link: http://blog.csdn.net/subaohao/article/details/9043895
In the activity placed 1 or more than 1 edittext, enter the activity when the first EditText will receive focus, I hope that all of the edittext in the default is not to receive focus, how to do it?
Method:
Add a linearlayout before the first edittext, and be sure to ask for the focus, otherwise it will not work. There's a lot of internet talk about adding a linearlayout, but there's no emphasis on using
<requestfocus/> This sentence, found that not to use this sentence is actually no effect.
<linearlayout
android:focusable= "true" android:focusableintouchmode= "true"
android:layout_width = "0px" android:layout_height= "0px" >
<requestfocus/>
</LinearLayout>
Then, all the edittext, inside do not use <requestfocus/>.
It was also said that after initialization, the call
EditText of Clearfocus (), i.e.:
EditText textin = (edittext) Findviewbyid (r.id.textinput);
Textin.clearfocus ();
Textin.setselected (FALSE);
Tried, but no effect.
How Android lets edittext not get focus automatically
In a project, as soon as you enter a page, EditText automatically gets the focus by default.
So how do you cancel this default behavior?
Looking for a long time on the internet, a bit of listening to soft keyboard events, a bit called Clearfouse () method, but the test did not. The corresponding property could not be found in the XML to turn off this default behavior
Solution: Find one in the parent control of the EditText, set to
Android:focusable= "true" android:focusableintouchmode= "true"
In this way, the default behavior of the EditText is truncated.
<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>