首页 > 解决方案 > 将菜单项添加到应用程序外部的弹出菜单

问题描述

正如您在图片中看到的那样,当您单击应用程序弹出菜单时会出现。默认情况下,此菜单有 2 个项目(应用信息和暂停应用)。如何向此弹出菜单添加额外的菜单项?

在此处输入图像描述

标签: androidandroid-menu

解决方案


我想你正在寻找这个

https://developer.android.com/guide/topics/ui/shortcuts

AndriodManifest.xml

<meta-data android:name="android.app.shortcuts"
       android:resource="@xml/shortcuts" />

创建一个新的资源文件:res/xml/shortcuts.xml

在文件中定义快捷方式

<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
 <shortcut
 android:shortcutId="compose"
 android:enabled="true"
 android:icon="@drawable/compose_icon"
 android:shortcutShortLabel="@string/compose_shortcut_short_label1"
 android:shortcutLongLabel="@string/compose_shortcut_long_label1"
 android:shortcutDisabledMessage="@string/compose_disabled_message1">
  <intent
   android:action="android.intent.action.VIEW"
   android:targetPackage="com.example.myapplication"
   android:targetClass="com.example.myapplication.ComposeActivity" />
   <!-- If your shortcut is associated with multiple intents, include them
     here. The last intent in the list determines what the user sees when
     they launch this shortcut. -->
   <categories android:name="android.shortcut.conversation" />
 </shortcut>
<!-- Specify more shortcuts here. -->
</shortcuts>

更多参考:https ://developer.android.com/guide/topics/ui/shortcuts/creating-shortcuts


推荐阅读