我正在搜索活动中使用 Android 搜索小部件进行搜索。它会自动获取焦点并显示软输入键盘。
然而,当用户使用 ActionBar 返回(但不是返回按钮)时,软输入键盘仍停留在屏幕上,即使活动已经关闭。
android:windowSoftInputMode="stateHidden|adjustUnspecified"
正如https://developer.android.com/training/keyboard-input/visibility.html所描述的那样,它似乎只在前进时起作用,而不是回退时。
问题:可能有许多活动调用SearchActivity,对于它们来说,使stateAlwaysHidden
可能不合适。(换句话说:我不知道所有其他活动的行为。)
更新:给出代码,实际上只是actionBar.setDisplayHomeAsUpEnabled(true);
@Override
protected void onCreate(Bundle savedInstanceState) {
....
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
// get the action bar
ActionBar actionBar = getActionBar();
if (null!=actionBar){
// Enabling Back navigation on Action Bar icon
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
....
}
更新2:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}
actionBar.setDisplayHomeAsUpEnabled(true);
。 - Paul Verestsuper
。然而,无论选择了哪个项目,onOptionsItemSelected
都是隐藏软输入的好地方... - Paul Verest