How does Android disable automatic focus Retrieval for edittext?

Source: Internet
Author: User

In the project, when you enter a page, edittext automatically obtains the focus by default.

So how to cancel this default behavior?

 

I have been searching for it online for a long time. I have listened to a soft keyboard event and called the clearfouse () method, but I have not tested it! You cannot find the corresponding attribute in XML to disable this default behavior.

 

Solution: find one in the parent control of edittext and set it

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

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