简体   繁体   中英

Focus on EditText is clear when click on it

My problem is when I click on EditText to input something, the keyboard appears, and the focus on EditText is disappeared, so I need to click again, and after that, I can type. What can be wrong? Code in XML is easy

    <androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/main_bg">

    <EditText
        android:id="@+id/et_phone"
        android:layout_width="0dp"
        android:layout_height="40dp"
        android:background="@drawable/bg_et"
        android:paddingVertical="4dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginTop="8dp"
        android:hint="@string/enter_phone_hint"
        android:paddingHorizontal="16dp"/>

Try to add windowSoftInputMode to your Activity in your Manifest file. Set it to adjustPan .

AndroidManifest.xml

<activity
        android:name=".MainActivity"
        android:exported="true"
        android:windowSoftInputMode="adjustPan">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM