diff --git a/android/modules/ui/src/java/ti/modules/titanium/ui/WindowProxy.java b/android/modules/ui/src/java/ti/modules/titanium/ui/WindowProxy.java index f1f8e5ced10..460883b49aa 100644 --- a/android/modules/ui/src/java/ti/modules/titanium/ui/WindowProxy.java +++ b/android/modules/ui/src/java/ti/modules/titanium/ui/WindowProxy.java @@ -45,6 +45,10 @@ import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; + +import android.text.Spannable; +import android.text.SpannableStringBuilder; +import android.text.style.ForegroundColorSpan; import android.transition.ChangeBounds; import android.transition.ChangeClipBounds; import android.transition.ChangeImageTransform; @@ -314,12 +318,42 @@ public void windowCreated(TiBaseActivity activity, Bundle savedInstanceState) Log.w(TAG, "Trying to set a barColor on a Window with ActionBar disabled. Property will be ignored."); } } + + // Handle titleAttributes property. + if (hasProperty(TiC.PROPERTY_TITLE_ATTRIBUTES)) { + KrollDict innerAttributes = getProperties().getKrollDict(TiC.PROPERTY_TITLE_ATTRIBUTES); + int colorInt = TiColorHelper.parseColor( + TiConvert.toString(innerAttributes.getString(TiC.PROPERTY_COLOR)), activity); + ActionBar actionBar = activity.getSupportActionBar(); + + if (actionBar != null) { + changeTitleColor(actionBar, colorInt); + } else { + Log.w(TAG, + "Trying to set a titleAttributes on a Window with ActionBar disabled. Property will be ignored."); + } + } activity.getActivityProxy().getDecorView().add(this); // Need to handle the cached activity proxy properties and url window in the JS side. callPropertySync(PROPERTY_POST_WINDOW_CREATED, null); } + private void changeTitleColor(ActionBar actionBar, int colorInt) + { + SpannableStringBuilder ssb; + if (actionBar.getTitle() instanceof SpannableStringBuilder) { + ssb = (SpannableStringBuilder) actionBar.getTitle(); + } else { + String abTitle = TiConvert.toString(actionBar.getTitle()); + ssb = new SpannableStringBuilder(abTitle); + } + + ssb.setSpan(new ForegroundColorSpan(colorInt), + 0, ssb.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); + actionBar.setTitle(ssb); + } + @Override public void onWindowActivityCreated() { @@ -409,6 +443,23 @@ public void onPropertyChanged(String name, Object value) } } } + + if (name.equals(TiC.PROPERTY_TITLE_ATTRIBUTES)) { + if (windowActivity != null && windowActivity.get() != null) { + // Get a reference to the ActionBar. + AppCompatActivity activity = windowActivity.get(); + ActionBar actionBar = activity.getSupportActionBar(); + // Check if it is available ( app is using a theme with one or a Toolbar is used as one ). + if (actionBar != null) { + HashMap innerAttributes = (HashMap) value; + changeTitleColor(actionBar, + TiConvert.toColor(innerAttributes.get(TiC.PROPERTY_COLOR), activity)); + } else { + // Log a warning if there is no ActionBar available. + Log.w(TAG, "There is no ActionBar available for this Window."); + } + } + } super.onPropertyChanged(name, value); } diff --git a/android/titanium/src/java/org/appcelerator/titanium/TiC.java b/android/titanium/src/java/org/appcelerator/titanium/TiC.java index ee351660934..704af44e031 100644 --- a/android/titanium/src/java/org/appcelerator/titanium/TiC.java +++ b/android/titanium/src/java/org/appcelerator/titanium/TiC.java @@ -773,6 +773,7 @@ public class TiC public static final String PROPERTY_TINT = "tint"; public static final String PROPERTY_TINT_COLOR = "tintColor"; public static final String PROPERTY_TITLE = "title"; + public static final String PROPERTY_TITLE_ATTRIBUTES = "titleAttributes"; public static final String PROPERTY_TITLE_COLOR = "titleColor"; public static final String PROPERTY_TITLE_CONDENSED = "titleCondensed"; public static final String PROPERTY_TITLEID = "titleid"; diff --git a/apidoc/Titanium/UI/Window.yml b/apidoc/Titanium/UI/Window.yml index df1b0e18325..bbc3aef2a6f 100644 --- a/apidoc/Titanium/UI/Window.yml +++ b/apidoc/Titanium/UI/Window.yml @@ -1409,8 +1409,8 @@ properties: summary: Title text attributes of the window. description: | Use this property to specify the color, font and shadow attributes of the title. - platforms: [iphone, ipad, macos] - since: {iphone: "3.2.0", ipad: "3.2.0", macos: "9.2.0"} + platforms: [android, iphone, ipad, macos] + since: {android: "12.3.0", iphone: "3.2.0", ipad: "3.2.0", macos: "9.2.0"} type: titleAttributesParams - name: titleControl @@ -1993,8 +1993,8 @@ properties: --- name: titleAttributesParams summary: Dictionary of options for the property. -platforms: [iphone, ipad, macos] -since: {iphone: "3.2.0", ipad: "3.2.0", macos: "9.2.0"} +platforms: [android, iphone, ipad, macos] +since: {android: "12.3.0", iphone: "3.2.0", ipad: "3.2.0", macos: "9.2.0"} examples: - title: Simple Example example: | @@ -2017,14 +2017,18 @@ properties: description: | For information about color values, see the "Colors" section of . type: [String, Titanium.UI.Color] + platforms: [android, iphone, ipad, macos] + since: {android: "12.3.0", iphone: "3.2.0", ipad: "3.2.0", macos: "9.2.0"} - name: font summary: Font to use for the window title. type: Font + platforms: [iphone, ipad, macos] - name: shadow summary: Shadow color and offset for the window title. type: shadowDict + platforms: [iphone, ipad, macos] --- name: shadowDict