Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 20, 2024

Conversation

m1ga
Copy link
Contributor

@m1ga m1ga commented May 23, 2024

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

@hansemannn hansemannn merged commit 803bd04 into master Aug 20, 2024
9 checks passed
@hansemannn hansemannn deleted the androidActionbarBackgrundImage branch August 20, 2024 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants