Android cancels the default behavior of EditText automatically getting focus

  • 2020-05-07 20:24:12
  • OfStack

In a project, 1 enters a page and EditText automatically gets focus by default.

So how do I cancel this default behavior?
Looking for a long time on the Internet, a little monitoring soft keyboard events, a little call clearFouse() method, but have not tested! There is no property in xml to turn off this default behavior
Solution: find one of EditText's parent controls and 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> 

Related articles: