Android: Hiding the keyboard in an overridden “Done” keypress of EditText

前端 未结 4 484
一向
一向 2020-12-30 06:17

I have used a bit of Android code to override the \"Done\" button in my EditText field:

   myEditField.setOnEditorActionListener(new TextView.OnEditorActionL         


        
4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-30 06:52

    I had the same problem. Immediately after editText VISIBILITY change from GONE to VISIBLE, I had to set the focus and display the soft keyboard. I achieved this using the following code:

            (new Handler()).postDelayed(new Runnable() {
    
            public void run() {              yourEditText.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN , 0, 0, 0));
                yourEditText.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP , 0, 0, 0));                       
    
            }
        }, 200);
    

提交回复
热议问题