编辑:看来我没有说清楚。我需要的是一种每当我替换所在片段时隐藏软键盘的方法。我该如何去做呢?
让我保持简单。我在 Tab Fragment 1.2 中有一个 EditText 框,按下时它显然会打开软键盘。当选项卡更改时如何隐藏它?我在 onTabSelected() 中尝试了以下操作,它似乎没有做任何事情
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
我现在已经尝试了一切。到目前为止,我找到的建议解决方案都没有以任何方式帮助我。
您可以以编程方式使用,捕获设备屏幕上活动活动的视图。
public final void onTabReselected(Tab tab, FragmentTransaction fragmentTransaction) {
View focus = getCurrentFocus();
if (focus != null) {
hiddenKeyboard(focus);
}
}
public final void onTabselected(Tab tab, FragmentTransaction fragmentTransaction) {
View focus = getCurrentFocus();
if (focus != null) {
hiddenKeyboard(focus);
}
}
public final void onTabUnselected(Tab tab, FragmentTransaction fragmentTransaction) {
View focus = getCurrentFocus();
if (focus != null) {
hiddenKeyboard(focus);
}
}
private void hiddenKeyboard(View v) {
InputMethodManager keyboard = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
keyboard.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)