關於隱藏、顯示虛擬鍵盤的問題:
(1)初始化InputMethodManager對象:
mImm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
private void hideSoftInput(IBinder windowToken, int flag) {
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
mImm.hideSoftInputFromWindow(windowToken, flag);
}
(3)顯示虛擬鍵盤函數:
private void showSoftInput(View view, int flag) {
view.setFocusableInTouchMode(true);
view.requestFocus();
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
mImm.showSoftInput(view, flag);
}
當首次啓動activity時,可以直接在onCreate中調用showSoftInput()方法;
非首次啓動(比如說activity失去焦點,進入後臺,然後再獲取焦點),在onResume中作如下處理:
EditTextObject.postDelayed(new Runnable() {
@Override
public void run() {
//showSoftInput()方法;
}
}, int delayTime);