问题
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?
回答1:
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();
回答2:
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
.
回答3:
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" />
回答4:
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.
回答5:
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)
}
}
回答6:
<activity
android:name=".activities.EmailLoginActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateVisible|adjustResize" />
Hope this helps you
来源:https://stackoverflow.com/questions/51949487/keyboard-doesnt-show-up-when-enter-to-activity-in-android-pie-api-28