Soft Keyboard shows up on EditText focus ONLY once

后端 未结 5 649
無奈伤痛
無奈伤痛 2020-11-30 06:08

Thanks for reading.

I am facing a strange problem: My app behavior is such that when the Activity starts, I requestFocus() on an Edi

5条回答
  •  一向
    一向 (楼主)
    2020-11-30 06:45

    Try to open and hide inside a Runnable as,

    TO OPEN

                     ettext.requestFocus();
                     ettext.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            InputMethodManager keyboard = (InputMethodManager)
                            getSystemService(Context.INPUT_METHOD_SERVICE);
                            keyboard.showSoftInput(ettext, 0);
                        }
                    },200);
    

    TO CLOSE

                        ettext.requestFocus();
                        ettext.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            InputMethodManager keyboard = (InputMethodManager)
                            getSystemService(Context.INPUT_METHOD_SERVICE);
                            keyboard.hideSoftInputFromWindow(ettext.
                                                             getWindowToken(), 0);
                        }
                    },200);
    

提交回复
热议问题