在给应用设计图标的时候,可能会遇到这样的需求,应用图标有老版和新版两种,而又想在桌面上同时显示这两个图标以对比效果。

一个应用本身只有一个自己的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的图标要更扁平化并且显得更暗一些。

参考

shortcut intent的设定:http://stackoverflow.com/questions/3332753/desktop-icon-link

构造bitmap:http://stackoverflow.com/questions/4955268/how-to-set-a-bitmap-from-resource

扩展

(删除shortcut):http://www.cnblogs.com/yeqw1985/archive/2013/02/06/2907704.html

(launcher中多icon)http://www.icodelogic.com/?p=383

最新文章

  1. Java中的URL类
  2. eclipse 安装svn插件
  3. java web项目导入到eclipse中变成了java项目的一种情况的解决办法
  4. ListView滑动位置精准记忆
  5. 利用sqlserver日志恢复数据
  6. html5 base64基础
  7. TFS 图标意思
  8. .Net程序员学习Linux(二)
  9. 【考虑周全+数学变形】【11月赛】Is it a fantastic matrix?
  10. ExtJs4.0入门错误
  11. 生产都消费者模式的一个demo,消费者设置缓存
  12. JAVA版A星算法实现
  13. (转载) ASP.NET(C#) Web Api 通过文件流下载文件到本地实例
  14. WinDbg调试 C# dmp
  15. Http协议请求头、响应头、响应码
  16. 1)python,现在用过的,后面推出每日练习语法与深度挖掘应用
  17. Linux基础(六) Vim之vundle插件
  18. LeetCode - Number of Distinct Islands
  19. 《FPGA全程进阶---实战演练》第四章之实验平台软硬件使用简介
  20. NISP视频知识点总结

热门文章

  1. [Android]使用Kotlin+Anko开发Android(一)
  2. unbuntu apahce 2 设置 多域名
  3. sqlite3 not found问题解决方法
  4. tomcat &lt;context path&gt;的意义及作用
  5. Hierarchyid 常用操作
  6. winform ListView应用之分组、重绘图标、网格线 (c# .net winform)
  7. 安卓普通类通过classloader访问资源文件
  8. SQL 扩展事件
  9. pom.xml 样例
  10. SQL Server 2000 sp2 及更低版本不受此版本的 Windows 支持