Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-28570] Android: Add "homeAsUpIndicator" custom icon support to ActionBar

GitHub Issuen/a
TypeNew Feature
PriorityLow
StatusClosed
ResolutionFixed
Resolution Date2021-10-29T22:36:01.000+0000
Affected Version/sn/a
Fix Version/sRelease 10.2.0
ComponentsAndroid
LabelsActionBar, android, icon
ReporterJoshua Quick
AssigneeJoshua Quick
Created2021-10-27T21:55:38.000+0000
Updated2021-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 \[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

FileDateSize
ic_baseline_close_24.xml2021-10-27T21:54:22.000+0000420

Comments

  1. Joshua Quick 2021-10-28

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

JSON Source