首页 > 其他 > 详细

应用多个icon的对比

时间:2014-01-25 14:21:16      阅读:405      评论:0      收藏:0      [点我收藏+]

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

   一个应用本身只有一个自己的icon,在AndroidManifest.xml文件中的<application>的android:icon属性中可以进行设置。不过Android系统本身Intent的shortcut属性可以将启动一个intent的方式保存到Android系统的桌面上,并且还可以设置相应的图片。微信中将好友“添加到桌面”的功能应该就是用shortcut的intent来实现的。这里借助于shortcut intent来实现多个应用icon的对比。具体代码如下

一、设置shortcut intent的代码

bubuko.com,布布扣
    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);
    }
bubuko.com,布布扣

二、AndroidManifest.xml文件中增加相应权限

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

三、用微信5.0和5.2的图标进行对比后的结果截图,可以看出5.2的图标要更扁平化并且显得更暗一些。

bubuko.com,布布扣

参考

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

应用多个icon的对比

原文:http://www.cnblogs.com/jiangz/p/3532736.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!