How to open a keyboard when "focus" on an EditText?

1

I have an EditText where I used requestFocus() to get focus from it. I put setFocus(true) and setFocusableInTouchMode too.

When I open the activity, requestFocus() works, but does not open the keyboard and TextWatcher that I use in the same activity does not receive the data I type in TextView (When I click EditText it opens the keyboard).

Does anyone know what it can be?

    
asked by anonymous 03.08.2016 / 22:06

4 answers

2

To show the keyboard you can do this:

EditText editText = (EditText) findViewById(R.id.editText);
editText.requestFocus();
getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);

or alternatively (I usually use it):

EditText editText = (EditText) findViewById(R.id.editText);
InputMethodManager imm=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
    
04.08.2016 / 00:13
0

If you only have one EditText in your activity you just use the following Attributes in your manifest.xml

 android:windowSoftInputMode="stateAlwaysVisible"

Where? :

 <activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:screenOrientation="portrait"
    android:windowSoftInputMode="stateAlwaysVisible" >

    ...................

  </activity>

This will not require the use of setFocus(true) , setFocusableInTouchMode() or requestFocus()

    
04.08.2016 / 10:27
0

Check if Manifest has this tag in activity:

   android:windowSoftInputMode="stateAlwaysHidden"

If you have, remove.

    
04.08.2016 / 21:56
0

For you to focus on EditText :

editText.requestFocus();

And to revert (throw):

editText.clearFocus();
    
05.10.2017 / 13:58