Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to set drawable 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 error occurred drawable appears.How can i do it?

like image 919
Elham Gdz Avatar asked Dec 11 '13 07:12

Elham Gdz


2 Answers

set 0 if you want to invisible image

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

For reference

Programmatically set left drawable in a TextView

like image 197
Gayathiri Avatar answered Nov 06 '22 09:11

Gayathiri


You can get the reference by invoke TextView.getCompoundDrawables() method, then set the right drawable's alpha to 0 (invisible) or 255 (visible).

like image 34
Tang Ke Avatar answered Nov 06 '22 10:11

Tang Ke