双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

Launcher 快捷方式图标处理疑问

唐小尘 唐小尘 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我想将Launcher上的快捷方式通过程序处理改成圆角的。

这里是处理图标的代码http://blog.csdn.net/Android_Tutor/archive/2010/11/02/5981753.aspx

我在Launcher.java的infoFromShortcutIntent方法中添加如下代码:

Bitmap bitmap1 = ImageUtil.drawableToBitmap(context.getPackageManager().getDefaultActivityIcon());
Bitmap zoomBitmap = ImageUtil.zoomBitmap(bitmap1, 60, 60);
icon = new BitmapDrawable(ImageUtil.getRoundedCornerBitmap(zoomBitmap, 10.0f));


完整的方法如下:

private static ApplicationInfo infoFromShortcutIntent(Context context, Intent data) {
Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Bitmap bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);

Drawable icon = null;
boolean filtered = false;
boolean customIcon = false;
ShortcutIconResource iconResource = null;

if (bitmap != null) {
icon = new FastBitmapDrawable(Utilities.createBitmapThumbnail(bitmap, context));
filtered = true;
customIcon = true;
} else {
Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
if (extra != null && extra instanceof ShortcutIconResource) {
try {
iconResource = (ShortcutIconResource) extra;
final PackageManager packageManager = context.getPackageManager();
Resources resources = packageManager.getResourcesForApplication(
iconResource.packageName);
final int id = resources.getIdentifier(iconResource.resourceName, null, null);
icon = resources.getDrawable(id);
} catch (Exception e) {
w(LOG_TAG, "Could not load shortcut icon: " + extra);
}
}
}

if (icon == null) {
icon = context.getPackageManager().getDefaultActivityIcon();
}
final ApplicationInfo info = new ApplicationInfo();
//info.icon = icon;
// modify start tang
Bitmap bitmap1 = ImageUtil.drawableToBitmap(context.getPackageManager().getDefaultActivityIcon());
Bitmap zoomBitmap = ImageUtil.zoomBitmap(bitmap1, 60, 60);
info.icon = new BitmapDrawable(ImageUtil.getRoundedCornerBitmap(zoomBitmap, 10.0f));
// modify end tang

info.filtered = filtered;
info.title = name;
info.intent = intent;
info.customIcon = customIcon;
info.iconResource = iconResource;

return info;
}


那位大哥做过的,提供思路,指点指点迷津,先谢谢了。
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
唐小尘
Android 80,489 成员 91,375 内容