大佬教程收集整理的这篇文章主要介绍了将菜单项添加到应用程序外部的弹出菜单 我想你正在寻找这个,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
正如您在图片中看到的,当您单击应用程序时会出现一个弹出菜单。默认情况下,此菜单有 2 个项目(应用信息和暂停应用)。如何向此弹出菜单添加额外的菜单项?
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://scheR_332_11845@as.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
,这些在 Android 中称为应用快捷方式。
为此,您必须创建一个名为 shortcuts.xml
的 xml 并在 AndroidManifest.xml
中做一些更改
在文件夹 shortcuts.xml
中创建一个名为 res/xml-v25/
的文件。这是因为在 v25 以上支持快捷方式
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://scheR_332_11845@as.android.com/apk/res/android">
<shortcut
android:enabled="true"
android:icon="@drawable/your_shortcut_icon"
android:shortcutId="custom_shortcut_id"
android:shortcutLongLabel="@String/shortcut_long_label"
android:shortcutShortLabel="@String/shortcut_short_label">
// Associate action with it.
<intent
android:action="android.intent.action.VIEW"
android:targetClass="com.package.MainActivity"
android:targetPackage="com.package"/>
</shortcut>
</shortcuts>
并在应用了 MAIN 和 LAUNCHER 意图过滤器的活动下的 AndroidManifest.xml
中。
...
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
// Add this meta-data
<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts"/>
</activity>
...
详情请参考这里
以上是大佬教程为你收集整理的将菜单项添加到应用程序外部的弹出菜单 我想你正在寻找这个全部内容,希望文章能够帮你解决将菜单项添加到应用程序外部的弹出菜单 我想你正在寻找这个所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。