Android Launcher 动态icon【时钟】【日历】

主要要的逻辑就是想办法替换掉应用icon的drawable,然后通过自定义drawable的方式来实现动态Icon。

直接贴代码吧,没什么难的。


首先在IconCache.java 中的修改


<pre name="code" class="java">    private static class CacheEntry {
        public Bitmap icon;
        public CharSequence title;
        public CharSequence contentDescription;
        public IconScript script;//icon的脚本
    }

    public IconScript getScript(Intent intent, UserHandleCompat user){
    	synchronized (mCache) {
    		 ComponentName component = intent.getComponent();
             if (component == null) {
                 return null;
             }
            LauncherActivityInfoCompat launcherActInfo = mLauncherApps.resolveActivity(intent, user);
            CacheEntry entry = cacheLocked(component, launcherActInfo, null, user, true, -1);
            return entry.script;
        }
    }

private CacheEntry cacheLocked(ComponentName componentName, LauncherActivityInfoCompat info,
            HashMap<Object, CharSequence> labelCache, UserHandleCompat user,
            boolean usePackageIcon, int unreadNum) {
<span style="white-space:pre">		</span>……
 <span style="white-space:pre">	</span>    if(componentName.getPackageName().equals("com.android.deskclock"))
            	entry.script = new ClockScript();
            if(componentName.getPackageName().equals("com.android.calendar"))
            	entry.script = new CalendarScript();
    
        return entry;
}


ShortcutInfo.java

    public IconScript getScript(IconCache iconCache){
    	return iconCache.getScript(promisedIntent != null ? promisedIntent : intent, user);
    }

BubbleTextView.java

public void applyFromShortcutInfo(ShortcutInfo info, IconCache iconCache,
            boolean setDefaultPad
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
如果你想在 Android 10 中的启动器图标上添加圆角,可以使用以下步骤: 1. 首先,在你的 `drawable` 文件夹中创建一个新的图标资源文件,并命名为 `ic_launcher_round.xml`。 2. 在文件中添加以下代码: ```xml <?xml version="1.0" encoding="utf-8"?> <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> <background android:drawable="@color/ic_launcher_background"/> <foreground android:drawable="@drawable/ic_launcher_foreground"/> </adaptive-icon> ``` 这段代码定义了一个自适应图标,并将背景设置为 `ic_launcher_background` 资源文件中的颜色,将前景设置为 `ic_launcher_foreground` 资源文件中的图标。 3. 接下来,在 `values` 文件夹中的 `styles.xml` 文件中添加以下代码: ```xml <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="android:roundIcon">@drawable/ic_launcher_round</item> </style> ``` 这段代码将你的应用程序主题与新的启动器图标关联起来。 4. 最后,在 `AndroidManifest.xml` 文件中的 `application` 标签中添加以下代码: ```xml <application ... android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round"> ... </application> ``` 这段代码将应用程序的默认图标设置为 `ic_launcher` 资源文件中的图标,并将圆角图标设置为 `ic_launcher_round` 资源文件中的图标。 完成这些步骤后,你的应用程序的启动器图标应该具有圆角效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值