Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-28547] Android: Menu item icon ignores theme if assigned a resource ID

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionFixed
Resolution Date2021-10-29T03:39:10.000+0000
Affected Version/sn/a
Fix Version/sRelease 10.2.0
ComponentsAndroid
Labelsandroid, drawable, menu, menuitem, resource, theme
ReporterJoshua Quick
AssigneeJoshua Quick
Created2021-10-06T23:49:56.000+0000
Updated2021-10-29T03:39:10.000+0000

Description

*Summary:* When assigning a MenuItem "icon" property a res drawable integer ID, the app's theme is wrongly ignored. This is only an issue if the drawable uses a color attribute/style. *Notes:* This is not an issue if the resource drawable has hard-coded colors. *Steps to reproduce:*

Use the below code as the "app.js".

Copy [^ic_baseline_delete_24.xml] to folder: ./platform/android/res/drawable

Build and run on Android.

const window = Ti.UI.createWindow();
window.activity.onCreateOptionsMenu = (e) => {
	const menuItem = e.menu.add({
		icon: Ti.App.Android.R.drawable.ic_baseline_delete_24,
		showAsAction: Ti.Android.SHOW_AS_ACTION_ALWAYS,
	});
	menuItem.addEventListener("click", () => {
		alert("Menu item clicked on.");
	});
};
window.open();
*Result:* In the top-right corner, notice the delete/trash icon is always displayed white. When the "light" theme is shown, the menu item can't be seen. It shouldn't be shown as white in the dark theme either and should be gray like bottom navigation icons. !MenuIconLight-Bad.png|thumbnail! !MenuItemDark-Bad.png|thumbnail! *Expected Result:* For the default Titanium light theme, the icon should be gray. !MenuIconLight-Good.png|thumbnail! !MenuItemDark-Good.png|thumbnail!

Attachments

FileDateSize
ic_baseline_close_24.xml2021-10-27T20:40:03.000+0000420
ic_baseline_delete_24.xml2021-10-06T23:42:56.000+0000402
MenuIconLight-Bad.png2021-10-06T23:52:20.000+0000397133
MenuIconLight-Good.png2021-10-06T23:52:20.000+0000398571
MenuItemDark-Bad.png2021-10-06T23:57:34.000+0000401287
MenuItemDark-Good.png2021-10-06T23:57:34.000+0000401203

Comments

  1. Joshua Quick 2021-10-07

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/13106
  2. Joshua Quick 2021-10-27

    There's still an issue where menu icon wrongly uses the activity context's theme, when it should use the ActionBar context theme instead. This is an issue if you use the Theme.Titanium.Light theme because it uses the Theme.MaterialComponents.Light.DarkActionBar which sets the "attr/colorControlNormal" differently than the activity.
  3. Joshua Quick 2021-10-27

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/13147

JSON Source