• Android(一) 动态菜单


    1.android的一个activity可以再选中某项之后按menu键弹出特定的菜单,也就是动态菜单。动态菜单的实现是靠menu类中的addIntentOptions函数实现的,具体的声明如下:

    int android.view.Menu.addIntentOptions(
      int groupId,
      int itemId,
      int order,
      ComponentName caller,
      Intent[] specifics,                ------------ action+uri的具体方式来增加激活相应activity的菜单项
      Intent intent,        ---------- categroy+uri这种一般形式来增加激活相应activity的菜单项
      int flags,
      MenuItem[] outSpecificItems)  ---------Optional array in which to place the menu items that were generated for each of the specifics that were requested.

    2.notepad源码示例

               Uri uri = ContentUris.withAppendedId(getIntent().getData(), getSelectedItemId());
    
    
                Intent[] specifics = new Intent[1];
                specifics[0] = new Intent(Intent.ACTION_EDIT, uri);
                MenuItem[] items = new MenuItem[1];
    
    
                Intent intent = new Intent(null, uri);
                intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
                menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, null, specifics, intent, 0, items);

    3.自己的测试代码:在notepad项目中增加一个activity并注册

            <activity android:name="MyAdd" android:label="@string/title_myadd"    -------菜单项显示的名称
                    android:windowSoftInputMode="stateVisible">
                <intent-filter android:label="@string/resolve_myadd">
                    <action android:name="com.android.notepad.action.MYADD" />
                    <category android:name="android.intent.category.ALTERNATIVE" />
                    <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
                </intent-filter>
            </activity>
  • 相关阅读:
    CF949C Data Center Maintenance 题解
    P1438 无聊的数列 题解
    CF620E New Year Tree 题解
    结构体优先队列的定义
    CF464E The Classic Problem 题解
    CF427C Checkposts
    CF161D Distance in Tree 题解
    P4375 [USACO18OPEN]Out of Sorts G 题解
    SCI, SCIE, 和ESCI的区别
    Matlab画图中图的方法
  • 原文地址:https://www.cnblogs.com/yuyutianxia/p/3291128.html
Copyright © 2020-2023  润新知