13

I want to pop up the device keyboard when I enter to Email Login screen.

I declared the windowSoftInputMode to "stateVisible" in the AndroidManifest.xml file:

<activity
        android:name=".activities.EmailLoginActivity"
        android:launchMode="singleTask"
        android:screenOrientation="portrait"   
        android:windowSoftInputMode="stateVisible" />

I have followed this documentation.

Results:

On devices that run Android API up to 27, the keyboard is shown.

On devices that run the Android API 28, the keyboard is not shown.

Is it a bug in Android Pie?

Any suggestion?

Viraj Patel
  • 2,113
  • 16
  • 23
Elnatan Derech
  • 987
  • 2
  • 12
  • 18

6 Answers6

26

Seems in Android Pie (API 28), it is not setting request focus in EditText automatically.

So you have to set the requestFocus of your EditText either programmatically or in the XML file.

your_layout.xml

<EditText
        android:id="@+id/et_email"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/_20sdp"
        android:inputType="textEmailAddress"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <requestFocus />
    </EditText>

OR

your_activity.java

findViewById(R.id.et_email).requestFocus();
Viraj Patel
  • 2,113
  • 16
  • 23
  • If you are calling requestFocus() from onResume(), you will need to delay the call see https://stackoverflow.com/questions/5227118/android-show-soft-keyboard-when-first-activity-starts – Pig Dog Bay Jul 29 '19 at 14:23
1

I did have an issue with this as well for Android Pie. .requestFocus() didn't work for me.

Solution for my problem:

Make sure your EditText is actually visible. I used the EditText as a hidden field, and the keyboard only showed up after setting the width and height from 0 to 1dp.

Arieck
  • 2,002
  • 2
  • 9
  • 8
1

If you use hidden EditText with 0dp width and height, it won't work on API 28 pie, I was able to make it work by setting dimensions to 1dp and all parts of widget to transparent. This worked for me:

<EditText
        android:id="@+id/hacked_edit_text"
        android:layout_width="1dp"
        android:layout_height="1dp"
        android:background="@android:color/transparent"
        android:cursorVisible="false"
        android:textColor="@android:color/transparent" />
  • 1
    I have an EditText with the width and height set to wrap_content in an LinearLayout with the Visibility INVISIBLE for the LinearLayout. My EditText could not retrieve focus in Android Pie. I used this answer to set the width and height of my editText to 1dp, then it worked like a charm again. – 476rick Mar 22 '19 at 15:08
0

The problem with me was in device keyboard settings. Language and Input Default keyboard and change it to your device keyboard samsung in my case.

enter image description here

Jin Lee
  • 3,194
  • 12
  • 46
  • 86
0

It's nicely documented in official documentation:

fun showSoftKeyboard(view: View) {
    if (view.requestFocus()) {
        val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
        imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)
    }
}
David Vávra
  • 18,446
  • 7
  • 48
  • 56
-4
<activity
    android:name=".activities.EmailLoginActivity"
    android:launchMode="singleTask"
    android:screenOrientation="portrait"   
    android:windowSoftInputMode="stateVisible|adjustResize" />

Hope this helps you

Akash
  • 961
  • 6
  • 15