diff --git a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUITabbedBar.java b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUITabbedBar.java index 0486e21cd6e..8ca71d59e4b 100644 --- a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUITabbedBar.java +++ b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUITabbedBar.java @@ -10,6 +10,7 @@ import android.content.Context; import android.content.res.Configuration; import android.graphics.Color; +import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.view.MenuItem; import androidx.annotation.ColorInt; @@ -133,9 +134,11 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) // no selected color specified but a text color -> use that selectedTextColor = textColor; } - this.tabLayout.setTabTextColors(textColor, selectedTextColor); } + if (getProxy().hasPropertyAndNotNull(TiC.PROPERTY_ACTIVE_TINT_COLOR)) { + setTintColor(this.tabLayout.getTabAt(0), TiC.PROPERTY_ACTIVE_TINT_COLOR); + } setNativeView(this.tabLayout); } @@ -261,6 +264,10 @@ private void addItem(Object value) if (value instanceof Drawable) { tab.setIcon(((Drawable) value)); TiUITabLayoutTabGroup.scaleIconToFit(tab); + + if (proxy.hasPropertyAndNotNull(TiC.PROPERTY_TINT_COLOR)) { + setTintColor(tab, TiC.PROPERTY_TINT_COLOR); + } } else { tab.setText(value.toString()); } @@ -282,6 +289,14 @@ private void addItem(Object value) } } + private void setTintColor(TabLayout.Tab tab, String color) + { + if (tab != null && tab.getIcon() != null) { + tab.getIcon().setColorFilter(TiConvert.toColor(proxy.getProperty(color), + TiApplication.getAppCurrentActivity()), PorterDuff.Mode.SRC_IN); + } + } + // Handle switching styles after creation public void setNewStyle(int newStyle) { @@ -394,6 +409,10 @@ private void onTabIndexChangedTo(int index) // First, update the proxy's "index" property. proxy.setProperty(TiC.PROPERTY_INDEX, index); + if (proxy.hasPropertyAndNotNull(TiC.PROPERTY_ACTIVE_TINT_COLOR)) { + setTintColor(this.tabLayout.getTabAt(index), TiC.PROPERTY_ACTIVE_TINT_COLOR); + } + // Last, fire a "click" event. if (!skipClickEvent) { KrollDict data = new KrollDict(); @@ -406,7 +425,10 @@ private void onTabIndexChangedTo(int index) @Override public void onTabUnselected(TabLayout.Tab tab) { - // No override + // set old tint color again + if (proxy.hasPropertyAndNotNull(TiC.PROPERTY_TINT_COLOR)) { + setTintColor(tab, TiC.PROPERTY_TINT_COLOR); + } } @Override diff --git a/apidoc/Titanium/UI/TabbedBar.yml b/apidoc/Titanium/UI/TabbedBar.yml index 0e846c3b578..6857a5eda60 100644 --- a/apidoc/Titanium/UI/TabbedBar.yml +++ b/apidoc/Titanium/UI/TabbedBar.yml @@ -56,6 +56,12 @@ properties: availability: creation platforms: [iphone, ipad, android, macos] since: {iphone: "9.0.0", ipad: "9.0.0", android: "12.0.0"} + - name: activeTintColor + summary: Icon tint color of the selected tab + type: [ String, Titanium.UI.Color ] + availability: creation + platforms: [android] + since: {android: "12.5.0"} - name: style summary: Style of the tabbed bar. description: | @@ -66,7 +72,7 @@ properties: The `BAR` style specifies a more compact style and allows the bar's background color or gradient to show through. - + For Android use [Titanium.UI.TABS_STYLE_DEFAULT](Titanium.UI.TABS_STYLE_DEFAULT) or [Titanium.UI.TABS_STYLE_BOTTOM_NAVIGATION](Titanium.UI.TABS_STYLE_BOTTOM_NAVIGATION) and it is only supported in the creation dictionary of the proxy.