Erstellen Sie zunächst eine Farbauswahl in Resources/drawable/tab_icon_color.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#000000" android:state_selected="true" />
<item android:color="#F3F3F3" />
</selector>
Um eine ColorStateList
aus diesem xml zu erhalten:
var tabIconColors = Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop
? Resources.GetColorStateList(Resource.Drawable.home_tab_icon_color, Activity.Theme)
: Resources.GetColorStateList(Resource.Drawable.home_tab_icon_color);
Dann wird für jeden Reiter:
var tab = tabLayout.NewTab().SetIcon(Resource.Drawable.Whatever);
// we wrap the icon to support API < 21
var iconWrap = DrawableCompat.Wrap(tab.Icon);
DrawableCompat.SetTintList(iconWrap, tabIconColors);
tab.SetIcon(iconWrap);
tabLayout.AddTab(tab);
Ergebnisse (mit verschiedenen Farben obwohl):
Beachten Sie folgende Antworten - [David_E Antwort] (http://stackoverflow.com/a/30904139/4059570) - [Tako Antwort] (http://stackoverflow.com/a/33230289/4059570) – Andromer