Reputation: 1015
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?
Upvotes: 13
Views: 18164
Reputation: 41
-> If you want to Invisible 'android:drawableEndicon' then set
note :- Email is the findViewById of view like edittext
Email.setCompoundDrawablesWithIntrinsicBounds(0,0,0,0);
-> If you want to visible 'android:drawableEndicon' then set
Email.setCompoundDrawablesWithIntrinsicBounds(R.drawable.icon, 0, 0, 0);
Upvotes: 0
Reputation: 1508
You can get the reference by invoke TextView.getCompoundDrawables()
method, then set the right drawable's alpha to 0
(invisible) or 255
(visible).
Upvotes: 14
Reputation: 457
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
Upvotes: 22