Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android prevent EditText from requesting focus automatically

I have a quite simple Layout with an EditText and a button. The problem is the keyboard appears immediately after the activity is started and the EditText gets the focus. I removed the </requestFocus> from XML and I also don't do that in code. How can I prevent that behavior of EditText so the keyboard only appears after the used taps the editText?

like image 319
Droidman Avatar asked Jan 09 '13 15:01

Droidman


4 Answers

in your manifiest.xml write the below code in your activity

android:windowSoftInputMode="adjustNothing" 
like image 133
Dixit Patel Avatar answered Oct 22 '22 10:10

Dixit Patel


In your manifest.xml file, under the activity tag, place this:

android:windowSoftInputMode="stateHidden"
like image 38
Gridtestmail Avatar answered Oct 22 '22 08:10

Gridtestmail


try this

In your AndroidManifest.xml file write these lines

<activity
        android:configChanges="keyboardHidden|orientation"
        android:name=".YourActivityName"
        android:windowSoftInputMode="stateHidden" />

i just added details..

like image 20
Zar E Ahmer Avatar answered Oct 22 '22 09:10

Zar E Ahmer


From my POV a more elegant solution is:

  1. In XML add these lines to the main layout:

    <LinearLayout
        android:id="@+id/mainLayout"
        android:focusable="true"
        android:focusableInTouchMode="true"
        ...
        .../>
    
  2. And In Java in onCreate():

      LinearLayout mainLayout = (LinearLayout) findViewById(R.id.mainLayout);
      mainLayout.requestFocus();
    
like image 33
Artyom Okun Avatar answered Oct 22 '22 09:10

Artyom Okun