Skip to content

Commit 5a1fc84

Browse files
committed
fix(android): fix Actionbar backgroundImage doc and improve setter
1 parent bbde0c3 commit 5a1fc84

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

android/titanium/src/java/org/appcelerator/titanium/proxy/ActionBarProxy.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.appcelerator.titanium.TiC;
1616
import org.appcelerator.titanium.util.TiConvert;
1717
import org.appcelerator.titanium.util.TiUIHelper;
18+
import org.appcelerator.titanium.view.TiDrawableReference;
1819

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

104105
actionBar.setBackgroundDrawable(backgroundImage);
106+
} else {
107+
// fallback check with TiDrawableReference
108+
TiDrawableReference source = TiDrawableReference.fromUrl(this, url);
109+
if (source.getDrawable() != null) {
110+
actionBar.setDisplayShowTitleEnabled(!showTitleEnabled);
111+
actionBar.setDisplayShowTitleEnabled(showTitleEnabled);
112+
actionBar.setBackgroundDrawable(source.getDrawable());
113+
} else {
114+
// fail - show error
115+
Log.e(TAG, "Image " + url + " not found");
116+
}
105117
}
106118
}
107119

apidoc/Titanium/Android/ActionBar.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ examples:
5555
</Alloy>
5656
```
5757
58+
59+
`app/controllers/index.js`:
60+
```
61+
function doMenuClick() {}
62+
function openSettings() {}
63+
function doSearch() {}
64+
$.index.open();
65+
```
66+
5867
`app/styles/index.tss`:
5968
```
6069
"MenuItem": {
@@ -85,7 +94,7 @@ examples:
8594
win.activity.onCreate = () => {
8695
const actionBar = win.activity.actionBar;
8796
if (actionBar) {
88-
actionBar.backgroundImage = "/bg.png";
97+
actionBar.backgroundImage = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, 'bg.png').nativePath;
8998
actionBar.title = "New Title";
9099
actionBar.onHomeIconItemSelected = () => {
91100
Ti.API.info("Home icon clicked!");

0 commit comments

Comments
 (0)