Android固定快捷方式(Pin Shortcuts):如何移除‘1x1’标签?
Android固定快捷方式移除"1x1"标签解决方案
这个"1x1"标签是部分Launcher(比如Pixel系列原生Launcher)用来标识快捷方式的桌面网格占用尺寸,提示用户该快捷方式添加后会占据1x1的桌面格子。
要移除这个标签,核心是为快捷方式使用**自适应图标(Adaptive Icon)**替代普通图标,具体操作如下:
步骤1:创建自适应图标资源
在res/drawable目录下新建自适应图标XML文件(示例命名为ic_shortcut_adaptive.xml):
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> <background android:drawable="@color/shortcut_bg_color"/> <foreground android:drawable="@drawable/ic_shortcut_foreground"/> </adaptive-icon>
步骤2:构建ShortcutInfo时指定自适应图标
修改ShortcutInfo的构建逻辑,替换原图标为自适应图标:
ShortcutInfo.Builder shortcutBuilder = new ShortcutInfo.Builder(context, "unique_shortcut_id") .setShortLabel("自定义快捷方式") .setLongLabel("我的应用快捷方式") .setIcon(Icon.createWithResource(context, R.drawable.ic_shortcut_adaptive)) // 绑定自适应图标 .setIntent(new Intent(context, TargetActivity.class)); ShortcutInfo mShortcutInfo = shortcutBuilder.build();
原理说明
支持自适应图标的Launcher会默认隐藏尺寸标签,因为自适应图标本身就是为适配不同桌面网格设计的,系统判定它无需额外标注尺寸。如果仍无法移除,大概率是当前使用的Launcher存在自定义行为,这种情况无法通过应用代码强制修改。
内容的提问来源于stack exchange,提问作者toto_tata
相关产品推荐
相关产品推荐

