Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextInputEditText - Make clickable but not editable

I have a layout where I want to show a bunvh of edit texts and a date picker. Since I want to have the same design for all fields, I figured out that I need to user an edit text for date picker too but make it non editable but clickable. Below is the xml code of my edit text that will be used to show the date picker :

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/notification_layout"
    style="@style/Theme.Connect.InputFieldLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:startIconDrawable="@drawable/ic_stk_notification_24dp">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/notification_edit_text"
        style="@style/Theme.Connect.InputField"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Notification"
        android:maxLines="1"
        android:lines="1"
        android:cursorVisible="false"/>

</com.google.android.material.textfield.TextInputLayout>

I tried many solutions I found on the internet, I did managed to make edit text non editable but without the ripple click effect. Is there a way to make the edit text non edditable but still keep the ripple click effect? Is this the best practice to show a date picker consisting the design of the form layout?

like image 672
George Avatar asked May 06 '26 22:05

George


1 Answers

 Try this and change the `android:focusable` attribute to `false`                       


<com.google.android.material.textfield.TextInputLayout
      android:id="@+id/notification_layout"
       style="@style/Theme.Connect.InputFieldLayout"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     app:startIconDrawable="@drawable/ic_stk_notification_24dp">

<com.google.android.material.textfield.TextInputEditText
    android:id="@+id/notification_edit_text"
    style="@style/Theme.Connect.InputField"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Notification"
    android:maxLines="1"
    android:focusable="false"
    android:lines="1"
    android:cursorVisible="false"/>

</com.google.android.material.textfield.TextInputLayout>
like image 152
The Codepreneur Avatar answered May 08 '26 12:05

The Codepreneur



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!