Androidソフトキーボードのポップアップ問題のまとめ

2908 ワード

プロジェクトで使用されるソフトキーボードの管理は以下のようにまとめられています.
ページの開始時にキーボードをイジェクトしない
方法1:EditTextを含む外層レイアウトに追加
android:focusable="true"
android:focusableInTouchMode="true"

EditTextでフォーカスを取得すれば、
方法2:onResumeにこの行のコードを追加する
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE |
                WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

1、ソフトキーボードをEditTextにバインド:
edit.setFocusable(true);
			edit.setFocusableInTouchMode(true);
			edit.requestFocus();
			InputMethodManager inputManager = (InputMethodManager)edit.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
	        inputManager.showSoftInput(edit, 0);

2、ソフトキーボード表示を削除する:
editMsgView.setText("");
					editMsgView.clearFocus();
					//close InputMethodManager
					InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
					imm.hideSoftInputFromWindow(editMsgView.getWindowToken(), 0);
EditTextソフトウェアキーボードは常にイジェクトされません
EditText edit=(EditText)findViewById(R.id.edit); edit.setInputType(InputType.TYPE_NULL);
まあまあです
InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);   

  if(imm.isActive()){   //            

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

  }   

1,設定ソフトキーボードポップアップ属性インタフェースのロード後、ソフトキーボードがポップアップできず、ソフトキーボードがポップアップできない主な原因はAndroidプログラムが画面の描画を完了していないため、一定時間遅れてソフトキーボードをポップアップすることである.
方法1:
private Handler hander=new Handler(){
		public void handleMessage(android.os.Message msg) {
			edit.setFocusable(true);
			edit.setFocusableInTouchMode(true);
			edit.requestFocus();
			InputMethodManager inputManager = (InputMethodManager)edit.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
	        inputManager.showSoftInput(edit, 0);
		};
	};
@Override
		public void onWindowFocusChanged(boolean hasWindowFocus) {
			if(visible){	
				hander.sendEmptyMessageDelayed(0, 1000);
			}
		}

方法2:
Timer timer = new Timer();
timer.schedule(new TimerTask() {
	@Override
	public void run() {
		InputMethodManager m = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
		m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
	}
}, 300);


このActivityメインウィンドウは、常に画面のサイズを調整してソフトキーボードのスペースを残す