android任务切换,我可以为android任务切换器设置不同的图标吗?

从API21开始,开发者可以使用TaskDescription API来自定义应用在'最近的应用'屏幕中的图标和颜色。这段代码展示了如何在活动创建时设置TaskDescription,确保在最近任务列表中显示自定义图标。注意,最后一个设置TaskDescription的活动会决定最终展示样式。建议在MainActivity的onCreate()方法中放置此代码以获得最佳效果。
摘要由CSDN通过智能技术生成

是的,从API 21转发开始,我们可以选择使用

TaskDescription API在“最近的应用”屏幕中自定义应用的表示.

如果您只关心图标,则可以在活动中的任何位置使用此代码段:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

setTaskDescription(

new ActivityManager.TaskDescription(

null,// Leave the default title.

R.drawable.the_icon_you_want,null // Leave the default color

)

}

但是,您必须记住,应用程序在“最近的应用程序”屏幕上的演示文稿是由您设置的最后一个TaskDescription确定的.

正如Big Nerd Ranch关于这个问题的精彩文章所引述:

By default,the TaskDescription is based on the activity at the base of the task’s activity stack. Other activities that pile on will not affect the styling,unless those activities have a TaskDescription explicitly set at run time. The topmost activity with a TaskDescription explicitly set will trump the styling specified in the manifest or in activities below in the stack with TaskDescriptions set.

因此,为了获得最佳结果,您可能希望将该代码段放在应用程序的MainActivity的onCreate(..)方法中.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值