android – 按下主页键盘后没有隐藏
作者:互联网
我使用以下代码来显示键盘
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,
InputMethodManager.HIDE_IMPLICIT_ONLY);
我使用以下代码来隐藏键盘getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
隐藏键盘,和
也试过这个
InputMethodManager imm =(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
但按下主页后.应用关闭,但键盘在屏幕上保持不变.
请指导我.我究竟做错了什么?
我把我的隐藏代码.
我把hide放在onDestroy(),onBackPressed()和onOptionsItemSelected(MenuItem item)抱歉我的代码格式化.
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.mylayout);
textTv=(EditText)findViewById(R.id.textview1);
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,
InputMethodManager.HIDE_IMPLICIT_ONLY);
if(getIntent().getExtras()!=null)
{
Bundle extra=getIntent().getExtras();
if(extra!=null)
{
// code
}
}
}
public void onBackPressed() {
// TODO Auto-generated method stub
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(noteTv.getWindowToken(), 0);
}
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
switch (item.getItemId()) {
case R.id.menu1:
//code
break;
case R.id.menu2:
//code
break;
}
解决方法:
尝试
@Override
protected void onPause() {
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(noteTv.getWindowToken(), 0);
super.onPause();
}
标签:android-keypad,android 来源: https://codeday.me/bug/20190729/1568532.html