Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making textinputlayout uneditable and setting click event on it

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>
like image 862
Android Developer Avatar asked Sep 30 '17 11:09

Android Developer


People also ask

How do I disable TextInputLayout padding?

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.

How do I remove TextInputLayout error?

Now you can simply do input. setError(..) for new error and input. setErrorEnabled(false) to remove it.


3 Answers

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) }
like image 85
hybrid Avatar answered Sep 21 '22 23:09

hybrid


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>
like image 30
Tomin B Azhakathu Avatar answered Sep 24 '22 23:09

Tomin B Azhakathu


  1. Set TextInputLayout android:clickable="true".

  2. Set TextInputEditText android:clickable="true" and android:focusable="false".

  3. 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.

like image 39
Johnny Five Avatar answered Sep 22 '22 23:09

Johnny Five