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>
  • 相关阅读:
    runloop源代码
    runloop的source
    How an Event Enters a Cocoa Application
    RunLoop主要处理以下6类事件
    NSRunloop总结
    performSelector与objc_msgSend
    iOSUI显示思想
    NSPort与NSRunloop的关系是流与消息调度的关系
    Core Animation 负责将bitmap绑定提交到 GPU-[CALayer _display]
    iOS构建流畅的交互界面--CPU,GPU资源消耗的原因和解决方案
  • 原文地址:https://www.cnblogs.com/yuyutianxia/p/3291128.html
Copyright © 2011-2022 走看看