簡體   English   中英

如何在android中動態更改APP圖標

[英]How to change APP icon dynamically in android

我已嘗試下面的代碼,以動態更改應用程序圖標,但沒有用。

表現:

<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中動態獲取應用程序圖標和設置圖標???

您無法動態修改應用程序圖標。 Gmail不會動態修改應用圖標。

主屏幕 - 實際顯示這些內容的應用程序 - 可以選擇將徽章應用於某些應用程序圖標。 您可以創建一個看起來像帶徽章的圖標的應用程序小部件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM