Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-12148] Android: Action Bar backgroundImage isn't set properly in click event handlers.

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2014-04-01T21:32:14.000+0000
Affected Version/sRelease 3.0.0
Fix Version/sRelease 3.3.0
ComponentsAndroid
Labelsmodule_actionbar, qe-closed-3.3.0, qe-testadded
ReporterArthur Evans
AssigneeBiju pm
Created2012-12-22T01:31:38.000+0000
Updated2014-07-29T07:28:05.000+0000

Description

When setting the actionBar.backgroundImage property from a window's "open" event handler, the change takes effect immediately. However, when setting the background from a click event handler, the change does _not_ take effect. If you subsequently set the action bar's title property, the previous backgroundImage change takes effect. In addition, when setting one of the actionBar properties, the following message is logged: [ERROR][Proxy ( 1017)] Unable to lookup Proxy.prototype.setProperty Test code:
var win = Ti.UI.createWindow({
	title : "Old Title",
	navBarHidden : false,
	layout : 'vertical'
});

var b1 = Ti.UI.createButton({
	title : "Set Background"
});

var b2 = Ti.UI.createButton({
	title : "Set Title"
});

var actionBar;

win.add(b1);
win.add(b2);

b1.addEventListener("click", function() {
	if (actionBar) {
		actionBar.backgroundImage = "/bg.png";

	} else {
		Ti.API.warn("Action bar not available.");
	}
});

b2.addEventListener("click", function() {
	if (actionBar) {
		actionBar.title = "New Title";

	} else {
		Ti.API.warn("Action bar not available.");
	}

})
win.addEventListener("click", function() {
	if (Ti.Platform.osname === "android") {
		if (! win.activity) {
			Ti.API.error("Can't access action bar on a lightweight window.");
		}
		actionBar = win.activity.actionBar;
	}
});

win.open();
To reproduce: Create a project, set up to build with targetSdkVersion=11 or higher and api-tool-level 14 or higher. Run app. Click "Set Background", then "Set Title". Note that background doesn't get set when you click Set Background, but DOES get set when you click "Set Title." Sometimes you need to repeat this cycle once or twice before the background appears. After the background has been set, clicking "Set Background" again causes the background to disappear, although no change should be evident.

Attachments

FileDateSize
bg.png2012-12-22T01:34:53.000+00007626

Comments

  1. Biju pm 2013-07-24

    PR :- https://github.com/appcelerator/titanium_mobile/pull/4480
  2. Neha Mittal 2014-04-24

    Verified fix using below code and environment: Appc Studio: 3.3.0.201404211130 SDK build: 3.3.0.v20140423155715 acs: 1.0.14 npm: 1.3.2 alloy: 1.4.0-dev CLI: titanium-3.3.0-dev titanium-code-processor:1.1.1-beta1 Xcode: 5.1.1 Osx: Mavericks(10.9.2) Device: Nexus 5(4.4.2)
       var win = Ti.UI.createWindow({
           title : "Old Title",
           navBarHidden : false,
           layout : 'vertical'
       });
        
       var b1 = Ti.UI.createButton({
           title : "Set Background"
       });
        
       var b2 = Ti.UI.createButton({
           title : "Set Title"
       });
        
       var actionBar;
        
       win.add(b1);
       win.add(b2);
        
       b1.addEventListener("click", function() {
           if (actionBar) {
               actionBar.backgroundImage = "/bg.png";
        
           } else {
               Ti.API.warn("Action bar not available.");
           }
       });
        
       b2.addEventListener("click", function() {
           if (actionBar) {
               actionBar.title = "New Title";
        
           } else {
               Ti.API.warn("Action bar not available.");
           }
           });
        win.addEventListener("open", function() {
           if (Ti.Platform.osname === "android") {
               if (! win.activity) {
                   Ti.API.error("Can't access action bar on a lightweight window.");
               }
               actionBar = win.activity.actionBar;
           }
       
       });
       
       win.open();
       
    ActionBar BackgroundImage is working as expected. Hence closing the issue.

JSON Source