Automatic popping up keyboard on start Activity

后端 未结 19 1069
醉梦人生
醉梦人生 2020-11-28 23:05

I got a relative simple question. I have an activity with a lot of EditText\'s in them. When I open the activity it automatically focusses to the first EditText and displays

19条回答
  •  执笔经年
    2020-11-28 23:33

    Accepted answer is not working for me, that's why give answer working solution, may be it is helpful !

    EditText edt = (EditText) findViewById(R.id.edt);
    edt.requestFocus();    
    edt.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN , 0, 0, 0));
    edt.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP , 0, 0, 0));
    

    Now keyboard is open enjoy :)

提交回复
热议问题