如何在Android中动态更改APP图标 [英] How to change APP icon dynamically in android

查看:281
本文介绍了如何在Android中动态更改APP图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了以下代码,以便动态更改应用程序图标,但无济于事.

I have tried below code in order to change application icon dynamically but no use.

清单:

<uses-permission android:name="com.android.launcher.action.INSTALL_SHORTCUT"/>

班级:

Intent myLauncherIntent = new Intent();
myLauncherIntent.setClassName("your.package.name", "YourLauncherActivityName");
myLauncherIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, myLauncherIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Application Name");
intent.putExtra
       (
        Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
        Intent.ShortcutIconResource.fromContext
                                    (
                                         getApplicationContext(),
                                         R.drawable.app_icon
                                    )
       );
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");

getApplicationContext().sendBroadcast(intent);

每当收到任何传入消息时,我都需要在应用程序图标上显示计数器我的应用程式,例如gmail应用程式.又怎样我可以获取应用程序图标吗?在android中动态设置图标??

I need to show counter on app icon whenever any incoming message comes to my app like gmail app. So How can i get app icon & set icon dynamically in android???

推荐答案

您无法动态修改应用程序图标.Gmail不会动态修改应用程序图标.

You cannot modify the app icon dynamically. Gmail does not modify the app icon dynamically.

主屏幕(实际上是显示这些内容的应用)可以选择将徽章应用到某些应用图标.然后,您可以创建一个看起来像带有徽章的图标的应用程序小部件.

A home screen -- being the app that actually displays these things -- could elect to apply a badge to certain app icons. And you can create an app widget that looks like an icon with a badge.

这篇关于如何在Android中动态更改APP图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆