MILAN MARWADI MILAN MARWADI - 2 months ago 11
Android Question

Remove focus from EditText and also keep it editable

I am using EditText but when activity is started my EditText is already focused. I want to remove focus and also make it editable on click.

Here is the code of my edittext.

<EditText
android:id="@+id/et_HotelLocation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:drawableLeft="@drawable/ic_edit_location_black_24dp"
android:drawablePadding="8dp"/>

Answer

You can create dummy layout as below which you should keep exactly above your EditText and then use nextFocusUp and nextFocusLeft as shown.

<LinearLayout
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:layout_width="0px"
            android:layout_height="0px"/>

        <EditText

            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="8dp"
             android:id="@+id/et"
            android:drawablePadding="8dp"
            android:nextFocusUp="@id/et"
            android:nextFocusLeft="@id/et"
            app:met_floatingLabel="normal" />