是的,从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(..)方法中.