android弹出软键盘

// 界面加载后弹出软键盘 --- 不能弹出软键盘的主要原因是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.

//这个方法在界面上切换输入法的功能,如果输入法出于现实状态,就将他隐藏,如果处于隐藏状态,就显示输入法。

//-----------------------------------------------------------------------

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

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

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

  }   

原文地址:https://www.cnblogs.com/error404/p/2128289.html