Setting the color of the text drawing

I am trying to change the color of a TextView Drawable in Xamarin.

In Java, you can do it like this:

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView txt = (TextView) findViewById(R.id.my_textview); setTextViewDrawableColor(txt, R.color.my_color); } private void setTextViewDrawableColor(TextView textView, int color) { for (Drawable drawable : textView.getCompoundDrawables()) { if (drawable != null) { drawable.setColorFilter(new PorterDuffColorFilter(getColor(color), PorterDuff.Mode.SRC_IN)); } } } 

How can I do something like this in Xamarin.Android?

+7
source share
2 answers

Try below solution

 private void setTextViewDrawableColor(TextView textView, int color) { for (Drawable drawable : textView.getCompoundDrawables()) { if (drawable != null) { drawable.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(textView.getContext(), color), PorterDuff.Mode.SRC_IN)); } } } 
+9
source

I use this in kotlin:

 tv.getCompoundDrawables()[0].setTint(//color) 
0
source

Source: https://habr.com/ru/post/1266644/


All Articles