且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

android弹出软键盘

更新时间:2021-10-30 12:08:42

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// 界面加载后弹出软键盘 --- 不能弹出软键盘的主要原因是Android程序未将屏幕绘制完成,所以延迟一定时间,弹出软键盘。
 
Timer timer = new Timer();
timer.schedule(new TimerTask(){
    @Override
    public void run() {
     App.imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
    }
}, 1000);
 
//这个InputMethodManager类里面的toggleSoftInput方法的API中的解释是:
 
//This method toggles the input method window display. If the input window is already displayed, it gets hidden. If not the input window will be displayed.
 
//这个方法在界面上切换输入法的功能,如果输入法出于现实状态,就将他隐藏,如果处于隐藏状态,就显示输入法。
1
 
1
//-----------------------------------------------------------------------

  InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);   

  if(imm.isActive()){   //这里可以判断也可以不判断

    imm.hideSoftInputFromWindow(v.getApplicationWindowToken(), 0 );   

  }   



本文转自java豆子博客园博客,原文链接:http://www.cnblogs.com/error404/archive/2011/08/05/2128289.html,如需转载请自行联系原作者