gpt4 book ai didi

android - 按下工具栏后退箭头时键盘保持打开状态

转载 作者:行者123 更新时间:2023-11-29 19:38:27 24 4
gpt4 key购买 nike

我遵循以下代码:-

 @Override
public boolean onOptionsItemSelected(MenuItem item) {
// handle arrow click here
if (item.getItemId() == android.R.id.home) {

finish();
overridePendingTransition(R.transition.right_in, R.transition.right_out);


}
return super.onOptionsItemSelected(item);
}

在这种情况下,当我的键盘打开并且我按下工具栏后退箭头时,键盘保持打开状态并且 Activity 完成。我尝试通过调用以下方法将键盘强行隐藏在 pause() 中,但在转换时看起来不太好:-

public static void hideKeyboard(Activity activity) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
//Find the currently focused view, so we can grab the correct window token from it.


View view = activity.getCurrentFocus();
//If no view currently has focus, create a new one, just so we can grab a window token from it
if (view == null) {
view = new View(activity);
}
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);

}

最佳答案

尝试在您的工具栏后退按钮中放入以下代码:

//Hide keyboard when button was clicked.
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0);

像这样:

 @Override
public boolean onOptionsItemSelected(MenuItem item) {
// handle arrow click here
if (item.getItemId() == android.R.id.home) {

finish();
overridePendingTransition(R.transition.right_in, R.transition.right_out);


}
//Hide keyboard when button was clicked.
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
return super.onOptionsItemSelected(item);
}

关于android - 按下工具栏后退箭头时键盘保持打开状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38982937/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com