[英]android prevent EditText from requesting focus automatically
I have a quite simple Layout with an EditText and a button. 我有一个非常简单的布局,带有EditText和一个按钮。 The problem is the keyboard appears immediately after the activity is started and the EditText gets the focus.
问题是在活动开始后立即出现键盘并且EditText获得焦点。 I removed the
</requestFocus>
from XML and I also don't do that in code. 我从XML中删除了
</requestFocus>
,我也没有在代码中执行此操作。 How can I prevent that behavior of EditText so the keyboard only appears after the used taps the editText? 如何防止EditText的这种行为,以便键盘仅在使用后点击editText后出现?
在您的manifiest.xml
,在您的activity
编写以下代码
android:windowSoftInputMode="adjustNothing"
在manifest.xml
文件的activity标记下,放置:
android:windowSoftInputMode="stateHidden"
try this 试试这个
In your AndroidManifest.xml
file write these lines 在
AndroidManifest.xml
文件中写下这些行
<activity
android:configChanges="keyboardHidden|orientation"
android:name=".YourActivityName"
android:windowSoftInputMode="stateHidden" />
i just added details.. 我刚刚添加了细节..
From my POV a more elegant solution is: 从我的POV来看,更优雅的解决方案是:
In XML add these lines to the main layout: 在XML中将这些行添加到主布局:
<LinearLayout android:id="@+id/mainLayout" android:focusable="true" android:focusableInTouchMode="true" ... .../>
And In Java in onCreate(): 在onCreate()中的Java中:
LinearLayout mainLayout = (LinearLayout) findViewById(R.id.mainLayout); mainLayout.requestFocus();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.