Android之软键盘自动弹出和关闭代码
一:软键盘自动弹出。
private EditText top_middle;//输入框
//-------------------------------------弹出软键盘-----------------------------------
top_middle.setFocusable(true);
top_middle.setFocusableInTouchMode(true);
top_middle.requestFocus();
InputMethodManager inputManager =
(InputMethodManager) top_middle.getContext().getSystemService(
Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(top_middle, 0);
Timer timer = new Timer();
timer.schedule(new TimerTask()
{
public void run()
{
InputMethodManager inputManager =
(InputMethodManager) top_middle.getContext().getSystemService(
Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(top_middle, 0);
}
},
998);
二:软键盘自动关闭。
//-----------------------------------软键盘自动关闭----------------------------------------
InputMethodManager imm = (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);
猜你喜欢
更多-
win键被锁怎么解锁
键盘 2023-12-30
-
键盘如何关闭Fn功能键恢复F1~F12
键盘 2016-08-10
-
特殊符号如何才能用键盘打出来(常用的特殊符号大全)
键盘 2016-11-07
-
win键和alt键功能互换怎么改回来
键盘 2023-12-30
-
键盘快捷键不能用了的原因及解决办法
键盘 2016-07-23