[TIMOB-28570] Android: Add "homeAsUpIndicator" custom icon support to ActionBar
| GitHub Issue | n/a |
|---|---|
| Type | New Feature |
| Priority | Low |
| Status | Closed |
| Resolution | Fixed |
| Resolution Date | 2021-10-29T22:36:01.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | Release 10.2.0 |
| Components | Android |
| Labels | ActionBar, android, icon |
| Reporter | Joshua Quick |
| Assignee | Joshua Quick |
| Created | 2021-10-27T21:55:38.000+0000 |
| Updated | 2021-10-29T22:36:05.000+0000 |
Description
*Summary:*
Titanium does not offer an API to set the home indicator to a custom icon on the ActionBar. This means it's currently limited to a back arrow or the hamburger icon. Ideally, we should add support for a custom icon such as a Create folder:
Verify you see a close
\[x\] button.
*To-Do:*
Add property "homeAsUpIndicator" property to Ti.Android.ActionBar. Have it call the Java [ActionBar.setHomeAsUpIndicator()](https://developer.android.com/reference/android/app/ActionBar#setHomeAsUpIndicator(int)) method. This property should support drawable resource ID (such as a vector drawable) or an image string path.
*Test:*
Use below code as the "app.js".
Create folder: ./platform/android/res/drawable
Copy [^ic_baseline_close_24.xml] to above directory.
Build and run on Android.
Verify you see a close \[x\] button in top-left corner of action bar.
const window = Ti.UI.createWindow();
window.activity.onCreate = () => {
const actionBar = window.activity.actionBar;
actionBar.displayHomeAsUp = true;
actionBar.homeButtonEnabled = true;
actionBar.homeAsUpIndicator = Ti.App.Android.R.drawable.ic_baseline_close_24;
actionBar.onHomeIconItemSelected = () => {
alert("Clicked on ActionBar home icon.");
};
};
window.open();
*Work-Around:*
Use Titanium's Toolbar instead via its [navigationIcon](https://titaniumsdk.com/api/titanium/ui/toolbar.html#navigationicon) property. This is the equivalent of the ActionBar's home indicator, but takes more effort to implement.
Attachments
| File | Date | Size |
|---|---|---|
| ic_baseline_close_24.xml | 2021-10-27T21:54:22.000+0000 | 420 |
PR (master): https://github.com/appcelerator/titanium_mobile/pull/13149