How to show soft keyboard automatically when EditText gets focus

I want to show the keyboard when my EditText gets focus. I tried many methods, but nothing helped. I tried: 1.

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT); 

with different flags.

2. getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

  1. <requestFocus />

4.

  editText.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { editText.post(new Runnable() { @Override public void run() { InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); } }); } }); editText.requestFocus(); 

Method 4 is fork, but this is a bad solution. So here it says Show soft keyboard automatically when EditText gets focus

Before that, I used method 2 and it worked. but now no longer. and I created an empty project and it doesn't work, none of the methods

UPDATE:

 <style name="Theme.TransparencyDemo" parent="android:Theme.Light.NoTitleBar"> <item name="android:windowTranslucentStatus">true</item> <item name="android:windowTranslucentNavigation">true</item> </style> 
+4
source share
2 answers

You can also add flags to your activity, which will automatically display the keyboard

 <activity name="package.ActivityName" android:windowSoftInputMode="stateVisible"/> 

this is mostly useful if you expect the focus to be applied when the action starts

You can also use Fragment :

 InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); 

or activity

 InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); 
+7
source

Use WindowManager instead of InputMehtodManager inside the onFocusChange of the edittext listener, As its reliable.

 editText.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); } } }); 
+1
source

All Articles