How to Make edittext fail to get focus automatically

Source: Internet
Author: User

Address: http://blog.csdn.net/subaohao/article/details/9043895

One or more edittexts are placed in the activity. when entering the activity, the first edittext will receive the focus. I hope that all edittexts in the activity will not receive the focus by default, what should we do?
Method:
Add a linearlayout before the first edittext, And the request must obtain the focus; otherwise, the result is invalid. A linearlayout should be added on the Internet, but it is not emphasized to be used.
<Requestfocus/> This sentence does not work.

<LinearLayout        android:focusable="true" android:focusableInTouchMode="true"        android:layout_width="0px" android:layout_height="0px">        <requestFocus /> </LinearLayout>

Then, do not use <requestfocus/> for all edittexts.

Some people also say that after initialization

EditText的clearFocus(),即:
 EditText textIn = (EditText)findViewById(R.id.TextInput); textIn.clearFocus(); textIn.setSelected(false);
试过,但没有效果。

How does Android disable automatic focus Retrieval for edittext?

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> 

 

I haven't tried these methods, but I think the essence of these methods should be:

Transfers the focus of edittext to other controls. If edittext is in the first place, a hidden control should be defined before it, so that the focus is placed on the hidden control.

I will test all the methods in the future to verify if my ideas are correct !!

 

 

 

 

 



How to Make edittext unable to automatically get the focus ()

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.