如何在操作栏上添加下拉项 [英] How to add a Dropdown item on the action bar

查看:26
本文介绍了如何在操作栏上添加下拉项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Android Honeycomb 应用程序中,我使用 Tabs 作为导航样式.我想在溢出按钮旁边添加一个项目,但我希望该项目是一个下拉列表,用户将能够在那里选择一个选项,但与导航无关.什么是最简单的方法,因为我使用 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

In my Android Honeycomb application I use Tabs as the navigation style. I would like to add one item next to the overflow button, but I want that item to be a dropdown list, and the user will be able to select an option there, but not related to navigation. What is the easiest way since I'm using mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

是否可以不使用自定义视图来实现?

Is it possible to do it without using a custom view?

推荐答案

第一个选项:

menu/options.xml:

menu/options.xml:

<item
    android:icon="@drawable/ic_menu_sort"
    android:showAsAction="ifRoom">
    <menu>
        <item
            android:id="@+id/menuSortNewest"
            android:title="Sort by newest" />
        <item
            android:id="@+id/menuSortRating"
            android:title="Sort by rating" />
    </menu>
</item>

第二个选项:

menu/options.xml:

menu/options.xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/menuSort"
        android:showAsAction="ifRoom"
        android:actionLayout="@layout/action_sort"  />
</menu>

layout/action_sort.xml:

layout/action_sort.xml:

<Spinner xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/ic_menu_refresh"
    android:entries="@array/order" />

菜单资源文档 - http://developer.android.com/guide/topics/resources/menu-resource.html

这篇关于如何在操作栏上添加下拉项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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