android prevent EditText from requesting focus automatically

前端 未结 4 1258
情话喂你
情话喂你 2021-01-12 14:02

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

相关标签:
4条回答
  • 2021-01-12 14:24

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

    android:windowSoftInputMode="stateHidden"
    
    0 讨论(0)
  • 2021-01-12 14:26

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

    android:windowSoftInputMode="adjustNothing" 
    
    0 讨论(0)
  • 2021-01-12 14:29

    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..

    0 讨论(0)
  • 2021-01-12 14:41

    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();
      
    0 讨论(0)
提交回复
热议问题