سؤال

I'm using Titanium version 3.1.3 and alloy framework. I implemented the action bar in my app; but in the screen with tab groups in it, the title is missing from action bar. Only the icon is getting displayed in it. From this - https://jira.appcelerator.org/browse/TIMOB-11645, I can see that, this is fixed in SDK version: 3.1.0.v20130320190115. But still, I'm not able to figure out why.

I tried setting the title of action bar through code like this

var actionBar;
if (Ti.Platform.osname === "android") {
        if (! $.tab.activity) {
            Ti.API.error("Can't access action bar on a lightweight window.");
        } else {
            actionBar = $.tab.getActivity().actionBar;
            if (actionBar) {
                alert("true");
                //actionBar.title = "TITLE";
                actionBar.setTitle("TITLE");
            }
        }
    }

Please help. Thanks in advance!

هل كانت مفيدة؟

المحلول

In order to get access to some ActionBar methods and properties, like the title, your code needs to be run after the tabgroup is opened.

In your view, you can add event listener like this:

<TabGroup onOpen="doOpen">
    ....
</TabGroup>

Then in your controller, put your code in the callback:

function doOpen(){
    var actionBar;
    if (Ti.Platform.osname === "android") {
        if (! $.tab.activity) {
           Ti.API.error("Can't access action bar on a lightweight window.");
        } else {
            actionBar = $.tab.getActivity().actionBar;
            if (actionBar) {
                alert("true");
                //actionBar.title = "TITLE";
                actionBar.setTitle("TITLE");
            }
        }
    }
}

I tested your code in the open event callback using SDK 3.2.1, and it worked fine.

Here is another example for modifying the ActionBar title.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top