Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to setOnClickListener in TextInputLayout

Tags:

java

android

ttilLastDate = (TextInputLayout) view.findViewById(R.id.tilLastDate);
tilLastDate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.v("PublishTask","has click");
            }
        });

why the OnClickListener don't work?

like image 747
Zhang Huayan Avatar asked Apr 06 '16 11:04

Zhang Huayan


People also ask

How do I remove TextInputLayout error?

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

How do I remove the default padding in 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. Save this answer.

How do I change the line color in TextInputLayout?

To change the hint color you have to use these attributes: hintTextColor and android:textColorHint . To change the bottom line color you have to use the attribute: boxStrokeColor .


1 Answers

I faced the same issue and my solution was to use the setOnFocusChangeListener on the EditText inside the TextInputLayout.

This is an example using ButterKnife.

The Layout:

                    <android.support.design.widget.TextInputLayout
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1">

                        <android.support.design.widget.TextInputEditText
                            android:id="@+id/edit_text"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"/>
                    </android.support.design.widget.TextInputLayout>

The listener:

@OnFocusChange(R.id.edit_text)
public void actionOnEditText(View view, boolean hasFocus) {
    if (hasFocus)
        yourClickMethod();
}
like image 122
Miguel Beltran Avatar answered Oct 07 '22 05:10

Miguel Beltran