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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
in your manifiest.xml
write the below code in your activity
android:windowSoftInputMode="adjustNothing"
回答2:
In your manifest.xml
file, under the activity tag, place this:
android:windowSoftInputMode="stateHidden"
回答3:
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..
回答4:
From my POV a more elegant solution is:
In XML add these lines to the main layout:
<LinearLayout android:id="@+id/mainLayout" android:focusable="true" android:focusableInTouchMode="true" ... .../>
And In Java in onCreate():
LinearLayout mainLayout = (LinearLayout) findViewById(R.id.mainLayout); mainLayout.requestFocus();