0

チタン appcelerator で android アプリを開発しています。今私の問題は、アプリにアクションバーを追加し、その左右に2つのボタンを配置する必要があることです

しかし、アクションバーをうまく実装できません

アクションバーを表示するために次のことを行いましたが、アプリケーションがクラッシュするだけです。

    var win = Ti.UI.createWindow({
        title: _args.title,
        backgroundColor:'black',
        navBarHidden: false,
        containingTab: _args.containingTab,
        //tabGroup: _args.tabGroup,
        barImage:rootPath+'/Components/top_bg.jpg'
    });


var actionBar;
win.addEventListener("open", function() {
    if (Ti.Platform.osname === "android") {
        if (! win.activity) {
            Ti.API.error("Can't access action bar on a lightweight window.");
            alert("NOT ACTIVITY");
        } else {
            actionBar = win.activity.actionBar;
            if (actionBar) {
                alert("ACTIVITY");
                actionBar.backgroundImage = "/images/bg_top.png";
                actionBar.title = "New Title";
                actionBar.onHomeIconItemSelected = function() {
                    Ti.API.info("Home icon clicked!");
                };
            }
        }
    }
});

誰がどこで間違いを犯しているのか教えてもらえますか? または、私が従う必要があるものは他にありますか。

4

2 に答える 2

4

包み込んでみるonCreateOptionsMenu

   win.activity.onCreateOptionsMenu = function(e) {
        actionBar = win.activity.actionBar;
        if (actionBar) {
            alert("ACTIVITY");
            actionBar.backgroundImage = "/images/bg_top.png";
            actionBar.title = "New Title";
            actionBar.onHomeIconItemSelected = function() {
                Ti.API.info("Home icon clicked!");
            };
        } else {
            alert('missing action bar');
        }
     });
于 2013-07-04T01:42:26.380 に答える