zoukankan      html  css  js  c++  java
  • 应用多个icon的对比

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

       一个应用本身只有一个自己的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

  • 相关阅读:
    Redis 多项目序列化问题
    Java序列化的相关认知
    《Proxy系列专题》:代理模式(静态、JDK、CGLib)
    好文章地址
    @ServletComponentScan
    Spring 自动配置的原理
    B+Tree
    Sentinel
    ThreadPoolUtil
    UUID
  • 原文地址:https://www.cnblogs.com/jiangz/p/3532736.html
Copyright © 2011-2022 走看看