Show keyboard automatically

后端 未结 9 2196
悲哀的现实
悲哀的现实 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

    for me by adding this line android:windowSoftInputMode="stateVisible" in your manifest like this

    **<activity
                android:name=".mmmmm.zzzzzzz.yyyyyy.xxxxxx"
                android:windowSoftInputMode="stateVisible"
                android:label="@string/title_activity_print_recharge"></activity>**
    

    this is how I solved it

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2020-12-08 05:08

    Try this

    @Override
    public void onResume() {
       super.onResume();
       final View v = getDialog().findViewById(R.id.edit_text_id);
       v.post(new Runnable() {
          @Override
          public void run() {
            v.requestFocus();
            InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
            if (imm != null) imm.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT);
          }
       });
     }
    
    0 讨论(0)
提交回复
热议问题