[TIMOB-28559] Android: Modify Ti.UI.Button "image" to support "R.drawable" IDs
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | Low |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2021-10-19T22:04:12.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 10.2.0 |
Components | Android |
Labels | android, button, drawable, image, resource |
Reporter | Joshua Quick |
Assignee | Joshua Quick |
Created | 2021-10-15T23:49:20.000+0000 |
Updated | 2021-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
File | Date | Size |
---|---|---|
Button-Dark.png | 2021-10-15T23:56:37.000+0000 | 405087 |
Button-Light.png | 2021-10-15T23:56:37.000+0000 | 402953 |
PR (master): https://github.com/appcelerator/titanium_mobile/pull/13125