在我的应用程序中,当我从一个活动切换到另一个活动时,软键盘会自动弹出。
我有一个活动(比方说A)是我设置的
android:configChanges="keyboardHidden"
因为我不想在这个活动中使用键盘,但是当我从这个活动转到另一个包含Map和AutoComompleteTextView的活动(比方说B)时,键盘首先会自动弹出,然后关闭。
我在活动B上尝试的内容:在清单中我设置了
android:windowSoftInputMode="stateHidden|adjustResize"
在oncreate中
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
我还试着把这个放到OnCreate中
try{
View view = this.getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}catch (Exception e)
{
Log.e(TAG, "onCreate: keyboard crash");
e.printStackTrace();
}
我还试着将焦点设置在活动中的另一个视图上,比如(查看v1)
v1.requestFoucs();
我甚至试着把
android:focusableInTouchMode="true"
活动B上的每个组件。
但对我来说什么都不管用。
请帮助我解决这个问题,我已经尝试了所有接受的答案,属于以下链接列表:
OnScreen keyboard opens automatically when Activity starts
Automatic popping up keyboard on start Activity
How to avoid automatically appear android keyboard when activity start
这是我的AutoComompleteTextView
<AutoCompleteTextView
android:id="@+id/auto_serviceArea"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_weight=".5"
android:background="@android:color/transparent"
android:cursorVisible="false"
android:hint="@string/serviceArea"
android:padding="5dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:singleLine="true"/>
编辑1:我试着检查哪个视图获得了焦点,这样我就可以转移焦点了,在调试时,我从AutoCompleteTextView中移除了焦点,但当活动开始时,键盘仍然出现和消失。所以这不是一个自动完成聚焦的问题。
发布于 2016-12-20 18:13:33
如果你已经根据ques的链接尝试了所有被接受的ans,那么你为什么不试着调试你的启动活动,我的意思是你已经在上面放置了启动相应的活动的意图。当我调试我的一个应用程序时,我发现android软键盘有一个问题,即使在完成调用它的活动之后,它也不会关机,它会在屏幕上停留几秒钟,但这种情况并不经常发生。
所以我建议你也调试你的调用活动,试着把"focusable=false“放在你调用相应活动的组件上。
发布于 2016-12-20 15:43:53
简单地说,你需要做的就是给予
android:windowSoftInputMode="stateHidden"
在您的活动的清单文件中。
发布于 2016-12-20 16:47:21
在主xml标记中写下一行
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
如下所示
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainLayout"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true" >
https://stackoverflow.com/questions/41236819
复制相似问题