软键盘打开时是否可以触发事件

时间:2012-05-30 12:54:03

标签: android

我想在android中打开或关闭Softkey板时通知(事件监听器)?可能吗 ? 如果可能的话请告诉我。

3 个答案:

答案 0 :(得分:0)

你可以这样做:

public static InputMethodManager imm = null;
            if(!(imm==null)){

            imm.getEnabledInputMethodList();
            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,1);

            // here do whatever you want to do
            }else
            {


            }

答案 1 :(得分:0)

检测键盘当前是否打开:

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

//keyboard is visible       
if(imm != null) {
    //do something, e.g., hide the keyboard like so : 
    //imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
    //or fire an event like so:
    //mButton.performClick();
} else {
    //do something
}

答案 2 :(得分:0)

  setContentView(mView);
  mView.getViewTreeObserver().addOnGlobalLayoutListener(
    new OnGlobalLayoutListener() {
    @Override
    public void onGlobalLayout() {
        Rect r = new Rect();
        mView.getWindowVisibleDisplayFrame(r);
            int heightDiff = mView.getRootView().getHeight()
                        - (r.bottom - r.top);
        if (heightDiff > 100) {
        //Keybord Action change
                    }
    }
});