Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show keyboard automatically

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:

<EditText     android:id="@+id/edPswrd"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:ems="10"     android:inputType="textPassword" >      <requestFocus /> </EditText> 

When it shows for the first time I do not see the soft keyboard and have to press editText for it to receive focus and the keyboard appears. Another activities are different, when it appears on screen the keyboard are loaded without any help. I thought that

< requestFocus />

means that EditText will be focused and keyboard will appear, but I am wrong.

How should I manage what component will receive focus and keyboard will automatically appear.

like image 206
Foenix Avatar asked Feb 07 '13 19:02

Foenix


People also ask

How do I get my keyboard to automatically pop up?

Go to Start , then select Settings > Accessibility > Keyboard, and turn on the On-Screen Keyboard toggle. A keyboard that can be used to move around the screen and enter text will appear on the screen. The keyboard will remain on the screen until you close it.

How do I show keyboard on-screen?

Settings . At the bottom, select Advanced. Under "Accessibility," select Manage accessibility features. Under "Keyboard and text input," select Enable on-screen keyboard.

How do I make my keyboard pop up automatically Windows 10?

To make the Touch keyboard appear automatically in Windows 10, you need to open Windows Settings, and go to Devices > Typing. Then, toggle the Automatically show the touch keyboard in windowed apps when there's no keyboard attached to your device button to turn it on.


1 Answers

I think it's a bug or a feature which tries to present the whole activity to you without obscuring it with the soft keyboard at first. I've searched once for information regarding that but unfortunately found nothing coming from a really reliable source.

Anyway, to show the soft keyboard you can do this:

EditText editText = (EditText)findViewById(R.id.edit_text_id); InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); 

I've also seen this code that should force the soft keyboard to become visible just after activity start, but never tried it:

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

And if you want to hide soft keyboard you can do this:

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(editText.getWindowToken(), 0); 

Hope that helps.

Edit:

For a DialogFragment this should work: in the onCreateView() method do this:

@Override public View onCreateView(LayoutInflater inflater, ViewGroup container,         Bundle savedInstanceState) {     View view = inflater.inflate(R.layout.fragment_id, container);     EditText editText = (EditText)view.findViewById(R.id.edit_text_id);      // show soft keyboard     editText.requestFocus();     getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);      return view; } 
like image 60
andr Avatar answered Sep 21 '22 15:09

andr