1818
1919
2020import android .content .Context ;
21+ import android .content .res .ColorStateList ;
2122import android .graphics .Canvas ;
2223import android .graphics .Color ;
2324import android .graphics .Paint ;
2627import android .view .View ;
2728import android .widget .LinearLayout ;
2829import android .widget .TextView ;
30+ import android .widget .ImageView ;
31+
32+ import androidx .core .widget .ImageViewCompat ;
2933
3034class TabStrip extends LinearLayout {
3135
@@ -51,6 +55,7 @@ class TabStrip extends LinearLayout {
5155 private int mTabTextColor ;
5256 private int mSelectedTabTextColor ;
5357 private float mTabTextFontSize ;
58+ private TabIconRenderingMode mIconRenderingMode ;
5459
5560 private boolean mShouldUpdateTabsTextColor ;
5661
@@ -88,6 +93,7 @@ class TabStrip extends LinearLayout {
8893
8994 // Default selected color is the same as mTabTextColor
9095 mSelectedTabTextColor = mTabTextColor ;
96+ mIconRenderingMode = TabIconRenderingMode .original ;
9197
9298 mShouldUpdateTabsTextColor = true ;
9399
@@ -106,6 +112,15 @@ void setSelectedIndicatorColors(int... colors) {
106112 invalidate ();
107113 }
108114
115+ void setIconRenderingMode (TabIconRenderingMode mode ) {
116+ mIconRenderingMode = mode ;
117+ updateTabsTextColor ();
118+ }
119+
120+ TabIconRenderingMode getIconRenderingMode () {
121+ return mIconRenderingMode ;
122+ }
123+
109124 void setTabTextColor (int color ){
110125 mTabTextColor = color ;
111126 updateTabsTextColor ();
@@ -128,16 +143,31 @@ void setShouldUpdateTabsTextColor(boolean value) {
128143 mShouldUpdateTabsTextColor = value ;
129144 }
130145
131- private void updateTabsTextColor (){
146+ private void updateTabsTextColor () {
132147 if (mShouldUpdateTabsTextColor ) {
133148 final int childCount = getChildCount ();
149+ int greyColor = Color .parseColor ("#A2A2A2" );
134150 for (int i = 0 ; i < childCount ; i ++){
135151 LinearLayout linearLayout = (LinearLayout )getChildAt (i );
152+ ImageView imageView = (ImageView )linearLayout .getChildAt (0 );
136153 TextView textView = (TextView )linearLayout .getChildAt (1 );
137- if (i == mSelectedPosition ){
138- textView .setTextColor (mSelectedTabTextColor );
154+
155+ if (mIconRenderingMode == TabIconRenderingMode .template ) {
156+ ColorStateList tint ;
157+ if (i == mSelectedPosition ) {
158+ tint = ColorStateList .valueOf (mSelectedTabTextColor );
159+ } else {
160+ tint = ColorStateList .valueOf (greyColor );
161+ }
162+
163+ ImageViewCompat .setImageTintList (imageView , tint );
164+ } else {
165+ ImageViewCompat .setImageTintList (imageView , null );
139166 }
140- else {
167+
168+ if (i == mSelectedPosition ) {
169+ textView .setTextColor (mSelectedTabTextColor );
170+ } else {
141171 textView .setTextColor (mTabTextColor );
142172 }
143173 }
0 commit comments