I want to make textinputlayout uneditable by user and when user click on it i want to perform an action.
I added android:focusable="false"
inside edittext of textinputlayout to make it uneditable but now when i click on it it is not getting callback inside onclicklistener of textinputlayout.
<android.support.design.widget.TextInputLayout
android:id="@+id/tipVideoFilePath"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/uploadVideo"
android:layout_toLeftOf="@+id/uploadVideo">
<EditText
android:id="@+id/etVideoFilePath"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/dp5"
android:singleLine="true"
android:focusable="false"
android:hint="@string/videoPath"
android:textColor="@color/black"/>
</android.support.design.widget.TextInputLayout>
You can just set the start and end padding on the inner EditText to 0dp. Here's a screenshot with Show Layout Bounds turned on so you can see that the hints go all the way to the edge of the view.
Now you can simply do input. setError(..) for new error and input. setErrorEnabled(false) to remove it.
I had the same issue for TextInputLayout
and TextInputEditText
. I wanted to open a dialog.
This worked for me
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/country_chooser_layout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/country_chooser"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:drawableEnd="@drawable/ic_expand_arrow"
android:focusable="false"
android:hint="Country"
android:inputType="textCapWords" />
</com.google.android.material.textfield.TextInputLayout>
Kotlin :
val countryChooser = view.findViewById<TextInputEditText>(R.id.country_chooser)
countryChooser.setOnClickListener { v -> showCountryDialog(v) }
Try this code. get on clck listener for the edittext.
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:id="+id/etVideoFilePat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:clickable="true" />
</android.support.design.widget.TextInputLayout>
Set TextInputLayout
android:clickable="true"
.
Set TextInputEditText
android:clickable="true"
and android:focusable="false"
.
Set View.OnClickListener
on both TextInputLayout
and TextInputEditText
.
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="false"/>
</com.google.android.material.textfield.TextInputLayout>
Note: It's important to set View.OnClickListener
on both views because TextInputLayout
bigger than and behind TextInputEditText
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With