Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-28559] Android: Modify Ti.UI.Button "image" to support "R.drawable" IDs

GitHub Issuen/a
TypeImprovement
PriorityLow
StatusClosed
ResolutionFixed
Resolution Date2021-10-19T22:04:12.000+0000
Affected Version/sn/a
Fix Version/sRelease 10.2.0
ComponentsAndroid
Labelsandroid, button, drawable, image, resource
ReporterJoshua Quick
AssigneeJoshua Quick
Created2021-10-15T23:49:20.000+0000
Updated2021-10-19T22:04:42.000+0000

Description

*Summary:* The Ti.UI.Button "image" property currently only supports String paths and Ti.Blob objects. On Android, we should add support for native resource IDs to load drawables, such as vector drawables. These are more commonly used and Android Studio has a wizard dialog to easy generate standard material icons that most apps use. *To-Do:* Modify "image" property to also support Number type to be a resource ID from Ti.App.Android.R.drawable.*. We should change our Java drawable loading code to call the static TiDrawableReference.fromObject() instead, which already supports Number type as well as File type. https://github.com/appcelerator/titanium_mobile/blob/master/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUIButton.java#L145-L150 https://github.com/appcelerator/titanium_mobile/blob/master/android/titanium/src/java/org/appcelerator/titanium/view/TiDrawableReference.java#L303-L326 *Example:*
const window = Ti.UI.createWindow();
const imageButton = Ti.UI.createButton({
	title: "Delete",
	image: Ti.App.Android.R.drawable.titanium_icon_delete,
});
imageButton.addEventListener("click", () => {
	alert("Button clicked on.");
});
window.add(imageButton);
window.open();
!Button-Light.png|thumbnail! !Button-Dark.png|thumbnail!

Attachments

FileDateSize
Button-Dark.png2021-10-15T23:56:37.000+0000405087
Button-Light.png2021-10-15T23:56:37.000+0000402953

Comments

  1. Joshua Quick 2021-10-16

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

JSON Source