我可以为 android 任务切换器设置不同的图标吗?
Can I set a different icon for the android task switcher?
我的应用有一个徽标,我可以将其设为黑色或白色。我指定的启动器图标是黑色的,我想保持它的颜色。但是,我的应用程序使用的是深色主题,最近的应用程序堆栈中应用程序标题栏的颜色也是黑色的。黑色标题栏上的黑色图标看起来很难看,尤其是在白色文本旁边。这是帮助解释的屏幕截图:
是否可以为启动器和任务切换器指定不同的图标?
编辑:我看到 Chrome 这样做:它将它的任务切换器图标更改为当前站点的图标,所以除非 API 是私有的,否则我绝对知道这是可能的。
是的,从 API 21 开始,我们可以选择使用 TaskDescription
API.
自定义我们的应用程序在“最近使用的应用程序”屏幕中的表示
如果您只关心图标,基本上可以在 Activity
:
中的任何地方使用下面的代码片段
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(..)
方法中。
我的应用有一个徽标,我可以将其设为黑色或白色。我指定的启动器图标是黑色的,我想保持它的颜色。但是,我的应用程序使用的是深色主题,最近的应用程序堆栈中应用程序标题栏的颜色也是黑色的。黑色标题栏上的黑色图标看起来很难看,尤其是在白色文本旁边。这是帮助解释的屏幕截图:
是否可以为启动器和任务切换器指定不同的图标?
编辑:我看到 Chrome 这样做:它将它的任务切换器图标更改为当前站点的图标,所以除非 API 是私有的,否则我绝对知道这是可能的。
是的,从 API 21 开始,我们可以选择使用 TaskDescription
API.
如果您只关心图标,基本上可以在 Activity
:
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(..)
方法中。