android 8以上桌面图标适配方案(圆形)

依赖文件:SVG格式桌面图标一张,符合标准的任意尺寸,例如72*72、96*96 、144*144
操作流程:

  • 使用Android studio转换
  1. 在 Android Studio 的项目中,右键点击 res 文件夹。
  2. 选择 New > Image Asset
  3. 确保 Icon Type 为 "Launcher Icons (Adaptive and Legacy)"。
  4. Path 字段中,选择一张源图像(例如,高分辨率的 PNG 或 SVG 文件)。这里使用****SVG,因为它可以无损缩放。
  5. 配置图标的外观(前景层、背景层、颜色等)。
  6. 关键一步:Legacy 标签页下,确保勾选了 Round Icon 选项。这就是告诉 Image Asset Studio 为你生成 ic_launcher_round.png 文件。
  7. 点击 Next,然后点击 Finish

二、 对android 8以上的手机进行适配

  • 在res目录创建文件夹mipmap-anyapi-v26

在文件内部再创建两个文件app_icon.xml、app_icon_round.xml,分别用于圆角桌面图标与圆形桌面图标

app_icon.xml文件内容:

html 复制代码
<?xml version="1.0" encoding="utf-8"?>

<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">

<background android:drawable="@drawable/ic_launcher_background"/>

<foreground android:drawable="@drawable/ic_luncher_by_svg"/>

</adaptive-icon>

app_icon_round.xml文件内容:

html 复制代码
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background"/>
<foreground android:drawable="@drawable/ic_luncher_round_by_svg"/>
</adaptive-icon>
  • 代码调整参数:

对svg文件转化生成的xml文件,改变内容区域(path属性)

例如:在原来图片基础上缩小内容区域0.7倍,图片上移三个像素

html 复制代码
<group 
    android:pivotX="75"
     android:pivotY="75" 
    android:scaleX="0.7" 
    android:scaleY="0.7" 
    android:translateY="-3">

三、android 8以前的手机则按照原来的方案,使用png

相关推荐
summerkissyou19873 小时前
Android - 摄像头 - hal - 开发教程,例子,常见问题,分析方法,解决方案
android
summerkissyou19874 小时前
Android 16 架构图
android
神龙天舞20015 小时前
MySQL 备库为什么会延迟好几个小时
android·数据库·mysql
码农coding8 小时前
android12 systemUI 之锁屏
android
圆山猫8 小时前
[Virtualization](三):RISC-V H-extension 与 Guest 执行模式
android·java·risc-v
爱笑鱼8 小时前
Binder(七):getCallingUid() 读到的是谁?clearCallingIdentity() 又清掉了什么?
android
2501_9159090614 小时前
iOS 应用反调试技详解术 检测调试器的原理与防护实践
android·ios·小程序·https·uni-app·iphone·webview
Lvan的前端笔记14 小时前
AndroidX 完全入门指南
android·androidx
帅次15 小时前
Android 应用高级面试:Window 近1年高频追问 18 题
android·面试·职场和发展
总捣什么乱115 小时前
MySQL MySQL是怎么保证主备一致的?
android·mysql·adb