zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    Linux网卡设置
    Linux虚拟机-----概述(1)
    Redis缓存数据库-----概述(1)
    Spring和Mybatis的集成
    onehot编码解释
    LINUX-CUDA版本所对应的NVIDIA驱动版本号,cuda版本报错的朋友参考一下
    matplotlib画图
    pytorch实现花朵数据集读取
    轻量架构ShuffleNet V2:从理论复杂度到实用设计准则
    CBAM: 卷积块注意模块
  • 原文地址:https://www.cnblogs.com/yuyutianxia/p/3291128.html
Copyright © 2011-2022 走看看