2

Is it possible to have nested context menus? I am working on an app which needs to provide the users with various functionality, and after much thought I came to the conclusion that using a context menu would be quite advantageous (would allow me to clean up my screen by getting rid of a few spinners etc)

However I was wondering if its even possible to have a context menu pop up, and then on the item select present the user with even more choices.

Something along these lines:

Context Menu 1 
 -> Change Font Color (on select generate context menu 2)
    ->Red
    ->Green
 -> Change Background Color (on select generate context menu 3)
    ->Red
    ->Green

Would something like this be possible?

4

1 回答 1

0

你用的是什么IDE?你用 xml 或 Java 做什么?如果您使用的是 Eclipse,您可以在包含 xml 文件的“菜单”文件夹中创建一个菜单,然后使用他们的“管理器”创建一个子菜单。

这是一个名为 game_menu.xml 的示例菜单:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/new_game"
          android:icon="@drawable/ic_new_game"
          android:title="@string/new_game"
          android:showAsAction="ifRoom"/>
    <item android:id="@+id/help"
          android:icon="@drawable/ic_help"
          android:title="@string/help" />
</menu>

要创建子菜单,您必须“嵌套<menu>元素”

http://developer.android.com/guide/topics/ui/menus.html

转到在 XML 中定义菜单

于 2013-06-16T04:27:32.617 回答