【问题标题】:Titanium Alloy: Actionbar & DrawerMenu钛合金:Actionbar & DrawerMenu
【发布时间】:2015-03-01 18:58:55
【问题描述】:

最近我开始使用钛合金开发一个多平台应用程序。 我想要实现的一件事是在操作栏中(应用图标前面)有一个菜单按钮。

按下时,它会切换抽屉菜单。

经过一番调查,我没能找到可以同时为我提供两者的小部件/模块。所以我决定使用com.alcoapps.actionbarextrascom.mcongrove.slideMenu 的组合。

自定义操作栏和抽屉选项似乎都可以正常工作。

但问题是,它确实显示了“菜单”图像,它是可点击的,但我不知道如何将事件附加到它。

我尝试了几种方法,例如将事件绑定到整个操作栏。但我似乎找不到合适的绑定来完成此操作。

index.js

var abextras = require('com.alcoapps.actionbarextras');

$.MainWindow.on('open', function(evt) {

    // set extras once the Activity is available
    abextras.title = "Test Window";
    abextras.homeAsUpIcon = "/images/menu.png";
    //abextras.titleColor = "#840505";
    //abextras.subtitle = "for some extra action";
    //abextras.subtitleFont = "Chunkfive.otf";
    //abextras.subtitleColor = "#562A2A";
    //abextras.backgroundColor = "#F49127";


    var activity = evt.source.activity;

    if (activity) {
        activity.onCreateOptionsMenu = function(e) {

            e.menu.clear();


            activity.actionBar.displayHomeAsUp = true;
                        //abextras.setHomeAsUpIcon("/images/menu.png");

                        //activity.actionBar.addEventListener("click", function(ev) {
                        //  console.log("HI");
                        //});

        };
    }

    /*

     // now set the menus
     evt.source.activity.onCreateOptionsMenu = function(e) {

     // aboutBtn and creditsBtn will be displayed in the menu overflow

     aboutBtn = e.menu.add({
     title : "About",
     showAsAction : Ti.Android.SHOW_AS_ACTION_NEVER
     });
     aboutBtn.addEventListener("click", function(e) {
     console.log('Clicked on About');
     });
     creditsBtn = e.menu.add({
     title : "Credits",
     showAsAction : Ti.Android.SHOW_AS_ACTION_NEVER
     });
     creditsBtn.addEventListener("click", function(e) {
     console.log('Clicked on Credits');
     });
     // create the Share intent and add it to the ActionBar
     var intent = Ti.Android.createIntent({
     action : Ti.Android.ACTION_SEND,
     type : 'text/plain'
     });
     intent.putExtra(Ti.Android.EXTRA_TEXT, 'Hello world!');
     abextras.addShareAction({
     menu : e.menu,
     //intent : intent
     });

     };
     */
});

function doClick(e) {
    alert($.label.text);
}

// Create our node items
var nodes = [{
    menuHeader : "My Tabs",
    id : 0,
    title : "Home",
    image : "/images/home.png"
}, {
    id : 1,
    title : "Contact",
    image : "/images/phone.png"
}, {
    id : 2,
    title : "Settings",
    image : "/images/gear.png"
}];

// Initialize the slide menu
$.SlideMenu.init({
    nodes : nodes,
    color : {
        headingBackground : "#000",
        headingText : "#FFF"
    }
});

// Set the first node as active
$.SlideMenu.setIndex(0);

// Add an event listener on the nodes
$.SlideMenu.Nodes.addEventListener("click", handleMenuClick);

// Handle the click event on a node
function handleMenuClick(_event) {
    if ( typeof _event.row.id !== "undefined") {
        // Open the corresponding controller
        openScreen(_event.row.id);
    }
}

function openMenu() {
    $.AppWrapper.animate({
        left : "300dp",
        duration : 250,
        curve : Ti.UI.ANIMATION_CURVE_EASE_IN_OUT
    });

    $.SlideMenu.Wrapper.animate({
        left : "0dp",
        duration : 250,
        curve : Ti.UI.ANIMATION_CURVE_EASE_IN_OUT
    });

    toggleMenu();
}

function closeMenu() {
    $.AppWrapper.animate({
        left : "0dp",
        duration : 250,
        curve : Ti.UI.ANIMATION_CURVE_EASE_IN_OUT
    });

    $.SlideMenu.Wrapper.animate({
        left : "-300dp",
        duration : 250,
        curve : Ti.UI.ANIMATION_CURVE_EASE_IN_OUT
    });

    toggleMenu();
}

function toggleMenu() {
    //
    console.log($.AppWrapper.left);
}

$.AppWrapper.addEventListener("swipe", function(_event) {
    if (_event.direction == "right") {
        openMenu();
    } else if (_event.direction == "left") {
        closeMenu();
    }
});

$.MainWindow.open();

//$.index.open();

index.xml

<Alloy>
    <Window class="container" id="MainWindow">
        <Require type="widget" src="com.mcongrove.slideMenu" id="SlideMenu" />

        <View id="AppWrapper">
            <Label text="Profile View" />
        </View>
    </Window>
</Alloy>

我希望对 Titanium 和/或这些模块有更多了解的人可以指导我。

亲切的问候,larssy1

【问题讨论】:

    标签: titanium titanium-mobile titanium-alloy titanium-modules titanium-widgets


    【解决方案1】:

    联系widget的创建者后,结果如下:

    var activity = evt.source.activity;      
    if (activity){
        activity.actionBar.onHomeIconItemSelected = function() {
           // your callback here
           alert('I was clicked');
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 2013-09-10
      • 2015-09-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多