Android之软键盘自动弹出和关闭【代码分享】
一:软键盘自动弹出。
privateEditTexttop_middle;//输入框
//-------------------------------------弹出软键盘-----------------------------------
top_middle.setFocusable(true);
top_middle.setFocusableInTouchMode(true);
top_middle.requestFocus();
InputMethodManagerinputManager=
(InputMethodManager)top_middle.getContext().getSystemService(
Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(top_middle,0);
Timertimer=newTimer();
timer.schedule(newTimerTask()
{
publicvoidrun()
{
InputMethodManagerinputManager=
(InputMethodManager)top_middle.getContext().getSystemService(
Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(top_middle,0);
}
},
998);
二:软键盘自动关闭。
//-----------------------------------软键盘自动关闭---------------------------------------- InputMethodManagerimm=(InputMethodManager)this.getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(top_middle.getWindowToken(),0);
三:对话框中软键盘自动弹出和关闭。
//--------------------------------对话框中自动弹出和关闭----------------------------------- getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE|WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持毛票票!