Skip to content

Commit

Permalink
fix(android): fix Actionbar backgroundImage doc and improve setter
Browse files Browse the repository at this point in the history
  • Loading branch information
m1ga committed May 23, 2024
1 parent bbde0c3 commit 5a1fc84
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiUIHelper;
import org.appcelerator.titanium.view.TiDrawableReference;

@SuppressWarnings("deprecation")
@Kroll.proxy(propertyAccessors = { TiC.PROPERTY_ON_HOME_ICON_ITEM_SELECTED, TiC.PROPERTY_CUSTOM_VIEW })
Expand Down Expand Up @@ -102,6 +103,17 @@ public void setBackgroundImage(String url)
actionBar.setDisplayShowTitleEnabled(showTitleEnabled);

actionBar.setBackgroundDrawable(backgroundImage);
} else {
// fallback check with TiDrawableReference
TiDrawableReference source = TiDrawableReference.fromUrl(this, url);
if (source.getDrawable() != null) {
actionBar.setDisplayShowTitleEnabled(!showTitleEnabled);
actionBar.setDisplayShowTitleEnabled(showTitleEnabled);
actionBar.setBackgroundDrawable(source.getDrawable());
} else {
// fail - show error
Log.e(TAG, "Image " + url + " not found");
}
}
}

Expand Down
11 changes: 10 additions & 1 deletion apidoc/Titanium/Android/ActionBar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ examples:
</Alloy>
```
`app/controllers/index.js`:
```
function doMenuClick() {}
function openSettings() {}
function doSearch() {}
$.index.open();
```
`app/styles/index.tss`:
```
"MenuItem": {
Expand Down Expand Up @@ -85,7 +94,7 @@ examples:
win.activity.onCreate = () => {
const actionBar = win.activity.actionBar;
if (actionBar) {
actionBar.backgroundImage = "/bg.png";
actionBar.backgroundImage = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, 'bg.png').nativePath;
actionBar.title = "New Title";
actionBar.onHomeIconItemSelected = () => {
Ti.API.info("Home icon clicked!");
Expand Down

0 comments on commit 5a1fc84

Please sign in to comment.