Android: how to set visible visible

This is my code:

<TextView android:id="@+id/error_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="2dp" android:drawablePadding="5dp" android:gravity="center" android:drawableRight="@drawable/error_image" android:textColor="#aa0000" android:textStyle="bold" android:textSize="16dp"/> 

I have a drawable that I want to set it invisible, and then when an error appears, drawable appears. How can i do this?

+6
source share
2 answers

set to 0 if you want an invisible image

 textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.icon, 0, 0, 0); 

For reference

Programmatically set left selection in TextView

+8
source

You can get the link by calling the TextView.getCompoundDrawables() method, then set the correct selected alpha to 0 (invisible) or 255 (visible).

+13
source

All Articles