Let EditText not get focus automatically

Source: Internet
Author: User
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> 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.