如何创建自定义下拉菜单,actionbarsherlock? [英] how to create custom drop down menu with actionbarsherlock?

查看:198
本文介绍了如何创建自定义下拉菜单,actionbarsherlock?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我试图模仿像潘多拉的菜单:

So, I'm trying to mimic something like Pandora's menu:

在这里您可以选择打在右上角,无论哪种方式菜单按钮或图标,就会显示出相同的下拉菜单列表。我试图创建一个溢出菜单中,但在较旧的设备我发现,菜单出现在底部还是(这是我不希望)。所以,我创建了一个微调和使用的:

Where you have the choice to hit the menu button or icon in the top right corner, either way, it will show the same drop down menu list. I've tried creating an 'overflow' menu but on older devices I found out that the menu appears at the bottom still (which I do not want). So I created a Spinner and used:

getSupportActionBar().setNavigationMode(getSupportActionBar().NAVIGATION_MODE_LIST);

使用这种方法的问题是,它显示一个项目的名称,而不是一个图标(我想我会提供一个图标,这是不是一个问题)和微调显示更向中部(其中,因为我想一路向右)。

The problem with this approach is that it displays the name of an item rather than an icon (I assume I would have to provide an icon which is not a problem) and the spinner displays more towards the middle (where as I want it all the way to the right).

所以,总括起来,有没有一种方法来创建一个菜单,类似于潘多拉的,即最右边的显示图标的动作条并通过图标或菜单按钮既是preSS打开?任何意见,建议或帮助将是很大的AP preciated,谢谢!

So, to sum it all up, is there a way to create a menu, similar to that of Pandora's, that displays an icon to the far right of the ActionBar and will open by both a press of the icon or menu button? Any advice, tips, or help would be greatly appreciated, thanks!

推荐答案

如果我理解你想创建一个弹出式菜单,并显示他们的时候在某些硬件按钮,用户点击图标了。

If I understood you want to create a popup menu and show they when the user click on her icon on in some hardware button.

好了, 是弹出了一个很好的解释菜单,如果你想获得一些设备密钥试试这个:

Well, here is a very good explanation of popup menus and if you want to get some device key try this:

public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_DPAD_CENTER:
        Toast.makeText(this, "The Center key was pressed",
                Toast.LENGTH_SHORT).show();
        return true;

    case KeyEvent.KEYCODE_DPAD_RIGHT:
        Toast.makeText(this, "The Right key was pressed",
                Toast.LENGTH_SHORT).show();
        return true;

    case KeyEvent.KEYCODE_DPAD_LEFT:
        Toast.makeText(this, "The Left key was pressed", Toast.LENGTH_SHORT)
                .show();
        return true;

    case KeyEvent.KEYCODE_BACK:
        Toast.makeText(this, "The Back key was pressed", Toast.LENGTH_SHORT)
                .show();

        //---this event has been handled---
        return true;
    }

    //---this event has not been handled---
    return false;
}

我希望这会帮助你。

I hope this will help you.

这篇关于如何创建自定义下拉菜单,actionbarsherlock?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆