【发布时间】:2017-05-05 08:16:25
【问题描述】:
在我的应用程序中,当我从一个活动转到另一个软键盘时会自动弹出。
我有一个活动(比如 A)我已经设置了
android:configChanges="keyboardHidden"
因为我不想在这个活动上使用键盘,但是当我从这个活动移动到另一个包含地图和 AutoComompleteTextView 的活动(比如 B)时,键盘首先会自动弹出然后关闭。
我对活动 B 的尝试: 在清单中我已经设置了
android:windowSoftInputMode="stateHidden|adjustResize"
在创建时
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();
}
我还尝试将焦点设置在活动中的另一个视图上,例如(View 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
这是我的自动完成文本视图
<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 中删除了焦点,但键盘仍然出现并在活动开始时消失。 所以这不是自动完成焦点问题。
【问题讨论】:
-
发布您的 edittext XML 布局。
-
xml 添加了@ahamed
-
@RajatPorwal 在 autocompleteTextView 中尝试
android:focusable="false"和android:focusableInTouchMode="true" -
@AkshayBhat'AB' 尝试不工作
标签: android keyboard android-softkeyboard autocompletetextview window-soft-input-mode