Android cancels EditText to automatically obtain the default focus behavior, androidedittext
Recently, when a new contact = in the address book enters a page, EditText automatically obtains the focus by default, which is very depressing. How can I disable EditText to automatically obtain the focus?
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"
Demo. xml:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff" android:baselineAligned="false" android:focusable="true" android:focusableInTouchMode="true" > <RelativeLayout android:layout_width="250dp" android:layout_height="wrap_content" android:id="@+id/txtLayout" android:layout_marginTop="20dp" android:layout_centerHorizontal="true" > <EditText android:layout_width="fill_parent" android:layout_height="35dp" android:id="@+id/editPhone" android:phoneNumber="true" android:text="@string/txtaddPhone" android:textColor="#D8D8D8" android:background="@drawable/txtupbg" android:textSize="15dp" /> </RelativeLayout> </RelativeLayout>