How to prevent keyboard from opening when opening activity in Android?

In my Android application, on the edit page of my profile, when I run the action, the first edittext field is focused (blinking with the cursor) and the keyboard is displayed.

How can I focus on starting (flashing cursor) but not showing the keyboard? If this is not possible, just do not focus the edittext at startup.

Thanks.

<EditText android:id="@+id/textinput_firstname" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:inputType="textPersonName" android:text="test" /> 
+4
source share
2 answers

Just add this line of code to your onCreate(...) method

 getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); 
+10
source

Just add this line of code to your Activity onCreate(...) method

 getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); 

add this line to manifest .

 android:windowSoftInputMode="stateHidden|adjustResize" 
0
source

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


All Articles