Android Autofocus text view when activity starts

I have an activity that has several EditText components.

When activity begins, the first of EditTexts becomes focused and a keyboard appears. I would like to avoid this โ€œfunctionโ€ (I mean that I want to not have a popup keyboard after starting the activity)

+4
source share
2 answers

Create a LinearLayout (I don't know if other kinds of layouts will work). Set the attributes android:focusable="true" and android:focusableInTouchMode="true" .

 <!-- Dummy item to prevent AutoCompleteTextView from receiving focus --> <LinearLayout android:focusable="true" android:focusableInTouchMode="true" android:layout_width="0px" android:layout_height="0px"/> <!-- :nextFocusUp and :nextFocusLeft have been set to the id of this component to prevent the dummy from receiving focus again --> <AutoCompleteTextView android:id="@+id/text" android:layout_width="fill_parent" android:layout_height="wrap_content" android:nextFocusUp="@+id/text" android:nextFocusLeft="@+id/text"/> 
+4
source

Try to add

Android: windowSoftInputMode = "adjustPan"

for an activity item in your manifest.

+1
source

Source: https://habr.com/ru/post/1335283/


All Articles