when click on editText show the android keyboard
How to show and hide keyboard in android.For examp开发者_StackOverflowle when i click on the editText keyboard should display and when i click outside of edittext keyboard should get hidden.
just try it..
InputMethodManager imm = (InputMethodManager)this.getSystemService(Service.INPUT_METHOD_SERVICE);
for hide keyboard
imm.hideSoftInputFromWindow(ed.getWindowToken(), 0);
for show keyboard
imm.showSoftInput(ed, 0);
where ed is EditText..
I've been using showSoftInput for a while but I've also found this alternative which simulates click on the EditText by using dispatchTouchEvent:
ed.requestFocus();
ed.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, 0, 0, 0));
ed.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, 0, 0, 0));
Didn't notice any difference though...
精彩评论