Show keyboard automatically

后端 未结 9 2223
悲哀的现实
悲哀的现实 2020-12-08 04:36

Please explain me the issue about soft keyboard. For example, I have an EditText on my activity or dialogfragment or fragmentactivity, whatever. here it is:

         


        
9条回答
  •  孤街浪徒
    2020-12-08 05:02

    This is what worked for me -

    Create your own EditText class and override following method -

    public class FocussableEditText extends EditText {
    
        public FocussableEditText(Context context) {
            super(context);
        }
    
        public FocussableEditText(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        public FocussableEditText(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }
    
        @Override
        public void onWindowFocusChanged(boolean hasWindowFocus) {
            super.onWindowFocusChanged(hasWindowFocus);
            if (hasWindowFocus) {
                InputMethodManager imm = (InputMethodManager)getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(this, InputMethodManager.SHOW_FORCED);
            }
        }
    }
    

    http://debuggingisfun.blogspot.in/2014/08/android-show-soft-keyboard.html

提交回复
热议问题