How Android lets EditText not automatically get focus

Source: Internet
Author: User

In a project, when you enter a page, EditText automatically gets the focus by default.

So how do you cancel this default behavior?

On the internet for a long time, a bit of listening to soft keyboard events, a little call Clearfouse () method, but the test is not! The corresponding attribute could not be found in XML to close this default behavior

Solution: Find one in EditText's parent control, set it to

Android:focusable= "true"
Android:focusableintouchmode= "true"

In this way, the default behavior of 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>

From: http://blog.csdn.net/a19860903/article/details/8546329 Grey often thanks to this classmate ...

There is also a way to implement this feature very simply:

The Clearfocus () of the EditText object;

Inputmethodmanager IMM = (inputmethodmanager) getsystemservice (Context.input_method_service);
Imm.hidesoftinputfromwindow (Editmsgview.getwindowtoken (), 0); (off soft keyboard ...) )

How Android lets EditText not automatically get focus

Related Article

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.