I'm adding/removing drawableLeft programmatically by:
((TextView)view).setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_icon, 0, 0, 0);
((TextView)view).setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
But because I'm using it in a list,
I need the option to remove the drawableLeft for the unselected rows without alignment issues.
What I want:
AAA
* BBB
CCC
What I'm getting:
AAA
* BBB
CCC
I can work around it by adding transparent icon,
but can I control this drawableLeft visibility programmatically?
I'm not sure exactly which type of view you're applying the drawable to, but you could simply set the left padding to match the width of the drawable when it's not present.
View.setPadding(left, 0, 0, 0);
if you are on API 23 or above you can use android:drawableTint="@android:color/transparent"
else you can use color filter. for example, hide the left drawable
Drawable[] drawables = tvLabel.getCompoundDrawables();
if (drawables[0] != null) {
drawables[0].mutate().setColorFilter(ContextCompat.getColor(getContext(),android.R.color.transparent), PorterDuff.Mode.MULTIPLY);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With