Search code examples
javaandroidfocusandroid-textinputlayout

Prevent Focus onCreate Activity


I need remove or prevent focus when activity start and i have used some code like:

android:focusableInTouchMode="true"

android:windowSoftInputMode="stateHidden"

But always on start the focus go in first TextInputLayout without keyboard

enter image description here


Solution

  • Try this

    Use android:windowSoftInputMode="stateAlwaysHidden" in manifest file

    And Use in your Root ConstraintLayout Layout

    android:focusable="true"
    android:focusableInTouchMode="true"
    

    SAMPLE CODE

    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:orientation="vertical"
        android:paddingLeft="16dp"
        android:paddingRight="16dp">