titanium-sdk icon indicating copy to clipboard operation
titanium-sdk copied to clipboard

fix(android): fix Actionbar backgroundImage doc and improve setter

Open m1ga opened this issue 1 month ago • 0 comments

The current ActionBar "backgroundImage" example: https://titaniumsdk.com/api/titanium/android/actionbar.html#action-bar-example says you can use "/bg.png" as a backgroundImage. That calls a function that will check for the String "Resources" in the path: https://github.com/tidev/titanium-sdk/blob/master/android/titanium/src/java/org/appcelerator/titanium/util/TiUIHelper.java#L983-L986 which is not the case.

The current workaround is to use Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, 'bg.png').nativePath; instead so I've added that in the classic example.

BUT I also made a change in the ActionBar so it will use images with just the image path as a string.

Changes:

  • at first it tries to use existing drawable code
  • if that fails it tries the new TiDrawableReference code (works with just the image file/path)
  • if both fail it will show an "image not found" error (new too)

Changes in the docs:

  • show that you can use the resources folder
  • add the missing index.js controller for the Alloy example

Test

const win = Ti.UI.createWindow({
	title: "Old Title",
	navBarHidden: false
});
if (OS_ANDROID) {
	win.activity.onCreate = () => {
		const actionBar = win.activity.actionBar;
		if (actionBar) {
			// actionBar.backgroundImage = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, '/images/bg_intro.jpg').nativePath;
			actionBar.backgroundImage = '/images/bg_intro.jpg';
			actionBar.title = "New Title";
			actionBar.onHomeIconItemSelected = () => {
				Ti.API.info("Home icon clicked!");
			};
		}
	};
}
win.open();
  • use actionBar.backgroundImage = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, '/images/bg_intro.jpg').nativePath; (will work with 12.3.0.GA too)
  • use actionBar.backgroundImage = '/images/bg_intro.jpg'; (will only work with this PR)
  • change it to a none existing image to see the error message

m1ga avatar May 23 '24 14:05 m1ga