简体   繁体   English

如何在android中动态更改APP图标

[英]How to change APP icon dynamically in android

I have tried below code in order to change application icon dynamically but no use. 我已尝试下面的代码,以动态更改应用程序图标,但没有用。

Manifest: 表现:

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

Class: 类:

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);

I need to show counter on app icon whenever any incoming message comes to my app like gmail app. 我需要在应用程序图标上显示计数器,只要有任何传入消息来到我的应用程序,如gmail应用程序 So How can i get app icon & set icon dynamically in android??? 那么如何在android中动态获取应用程序图标和设置图标???

You cannot modify the app icon dynamically. 您无法动态修改应用程序图标。 Gmail does not modify the app icon dynamically. Gmail不会动态修改应用图标。

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. 您可以创建一个看起来像带徽章的图标的应用程序小部件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM