當前位置:首頁 » 安卓系統 » android動態應用圖標

android動態應用圖標

發布時間: 2023-01-20 00:48:17

① Android 怎麼動態修改 app 的圖標啊

去清單文件
<application android:icon="@drawable/icon" android:label="@string/app_name"
android:name="com.entel.app.cmcc.setting.MyApplication" android:theme="@android:style/Theme.NoTitleBar"
android:debuggable="true">
<activity android:name=".Loading" android:label="@string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> 上面的Icon就是aPP的圖標

② Android開發:如何動態更換APP圖標

原理 :在Manifest文件中,使用<activity-alias>標簽為我們的啟動Activity准備多個別名,擁有<activity-alias>標簽的activity指向啟動Activity,每個擁有<activity-alias>標簽的Activity都可以單獨設置一個icon,在程序中我們動態設置<activity>和<activity-alias>的enabled屬性來實現替換圖標效果。

步驟

這個 <activity-alias> 標簽需要注意的地方如下:

(1)android:name屬性可以隨意起。

(2)android:enabled屬性要設為false,否則桌面會存在多個APP圖標。

(3)android:icon屬性設置為不同的圖標。

(4)android:targetActivity屬性要設為啟動的Activity。

(5)添加<intent-filter>那部分來使其作為啟動的Activity。

注意setComponentEnabledSetting()方法的第3個參數有兩個值供選擇:1(也就是PackageManager.DONT_KILL_APP)和0。這兩種參數對應兩種效果:當設為1時,當切換APP圖標時,會有幾秒鍾的延遲,並且在延遲期間不能點擊圖標進入APP;當設為0時,當切換APP圖標時,會立刻更換,但是應用會被強制退出並被清理掉。

存在的問題

需要將<activity>的enabled屬性設為enabled或者將APP卸載後才能編譯運行。

③ Android編程:關於自定義APK圖標(動態的設置)

void addShortcutToDesktop(){

Intent shortcut = new Intent(ACTION_INSTALL);

BitmapDrawable iconBitmapDrawabel = null;

// 獲取應用基本信息
String label = this.getPackageName();
PackageManager packageManager = getPackageManager();
try {
iconBitmapDrawabel = (BitmapDrawable) packageManager.getApplicationIcon(label);
} catch (NameNotFoundException e) {
e.printStackTrace();
}

// 設置屬性
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, label);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON, iconBitmapDrawabel.getBitmap());

// 是否允許重復創建 -- fase-->否
shortcut.putExtra("plicate", false);

// 設置啟動程序
ComponentName comp = new ComponentName(label,"." + this.getLocalClassName());
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));

sendBroadcast(shortcut);
}

android支持發送Intent.EXTRA_SHORTCUT_ICON_RESOURCE的方式添加圖標,這個是在activity中用的方法,怎麼自定義一看就懂了

熱點內容
真我手機如何修改登錄密碼 發布:2025-09-17 05:20:26 瀏覽:313
電腦配置怎麼說 發布:2025-09-17 04:37:45 瀏覽:1001
三質數編程 發布:2025-09-17 04:04:41 瀏覽:559
ftp伺服器密碼如何修改 發布:2025-09-17 03:48:07 瀏覽:303
python爬蟲豆瓣 發布:2025-09-17 03:41:59 瀏覽:210
我的世界國際版加入伺服器電腦版 發布:2025-09-17 03:41:14 瀏覽:941
附件上傳相片 發布:2025-09-17 03:39:53 瀏覽:442
微信賬號密碼組合是什麼 發布:2025-09-17 03:30:05 瀏覽:400
windows如何查看ftp安裝環境 發布:2025-09-17 03:30:02 瀏覽:918
java培訓機構推薦 發布:2025-09-17 03:20:58 瀏覽:93