在給應用設計表徵圖的時候,可能會遇到這樣的需求,應用表徵圖有老版和新版兩種,而又想在案頭上同時顯示這兩個表徵圖以對比效果。 一個應用本身只有一個自己的icon,在AndroidManifest.xml檔案中的<application>的android:icon屬性中可以進行設定。不過Android系統本身Intent的shortcut屬性可以將啟動一個intent的方式儲存到Android系統的案頭上,並且還可以設定相應的圖片。中將好友“添加到案頭”的功能應該就是用shortcut的intent來實現的。這裡藉助於shortcut intent來實現多個應用icon的對比。具體代碼如下 一、設定shortcut intent的代碼 複製代碼 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Intent shortcutIntent=new Intent(MainActivity.this,MainActivity.this.getClass()); final Intent icon1=new Intent(); icon1.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); icon1.putExtra(Intent.EXTRA_SHORTCUT_NAME, "原表徵圖"); icon1.putExtra(Intent.EXTRA_SHORTCUT_ICON,BitmapFactory.decodeResource(getResources(), R.drawable.icon1)); icon1.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); sendBroadcast(icon1); final Intent icon2=new Intent(); icon2.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); icon2.putExtra(Intent.EXTRA_SHORTCUT_NAME, "新表徵圖"); icon2.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapFactory.decodeResource(getResources(), R.drawable.icon2)); icon2.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); sendBroadcast(icon2); }複製代碼二、AndroidManifest.xml檔案中增加相應許可權 <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/> 三、用5.0和5.2的表徵圖進行對比後的結果,可以看出5.2的表徵圖要更扁平化並且顯得更暗一些。