如何在Swift、Xcode中添加用户上滑时显示的非常规应用图标?
上滑调出的最近任务(概览)界面空白图标配置方案
你提到的上滑展示的非常规应用图标,属于系统最近任务(Recents Screen)界面的Activity栈专属图标,默认不会直接复用应用级别的桌面图标,可按以下方案配置:
静态配置(固定图标场景适用)
打开项目AndroidManifest.xml文件,找到对应该显示空白图标的页面所属的Activity声明,单独为该Activity配置android:icon属性即可,示例配置如下:<activity android:name=".YourTargetActivity" <!-- 单独配置概览界面专属图标,资源建议存放在mipmap对应分辨率目录,尺寸不低于108*108dp --> android:icon="@mipmap/ic_recents_custom" android:exported="true"> </activity>动态配置(运行时需切换图标场景适用)
如果需要在应用运行时动态修改该位置的图标,可在对应Activity中调用setTaskDescription方法实现,代码示例如下:// Kotlin 实现代码 val customRecentsIcon = BitmapFactory.decodeResource(resources, R.mipmap.ic_recents_custom) val taskDesc = ActivityManager.TaskDescription( "页面展示名称", customRecentsIcon, ContextCompat.getColor(this, R.color.primary_color) ) setTaskDescription(taskDesc)// Java 实现代码 Bitmap customRecentsIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_recents_custom); ActivityManager.TaskDescription taskDesc = new ActivityManager.TaskDescription( "页面展示名称", customRecentsIcon, ContextCompat.getColor(this, R.color.primary_color) ); setTaskDescription(taskDesc);适配验证
配置完成后完全杀死应用进程,重新打开对应页面后上滑调出最近任务界面即可查看效果。如果仍显示空白,检查图标资源是否存在分辨率适配问题,部分国内定制ROM有专属的最近任务图标配置规则,可对应ROM开发文档做额外适配。
内容的提问来源于stack exchange,提问作者GSDV
相关产品推荐
相关产品推荐

