Elnatan Derech
Elnatan Derech

Reputation: 1037

Keyboard doesn't show up when enter to activity in Android Pie (API-28)

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?

Upvotes: 14

Views: 5988

Answers (6)

David V&#225;vra
David V&#225;vra

Reputation: 19159

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)
    }
}

Upvotes: 0

mohamed elagamy
mohamed elagamy

Reputation: 1

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

Upvotes: 0

Dmitriy Pavlukhin
Dmitriy Pavlukhin

Reputation: 419

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" />

Upvotes: 1

Arieck
Arieck

Reputation: 2070

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.

Upvotes: 1

Viraj Patel
Viraj Patel

Reputation: 2403

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();

Upvotes: 27

Akash
Akash

Reputation: 971

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

Hope this helps you

Upvotes: -4

Related Questions