Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I set a different icon for the android task switcher?

Tags:

android

icons

My app has a logo that I can make either black or white. The launcher icon I have specified is black, and I would like to keep it that color. However, my application is using a dark theme, and the color of the app title bar in the recent apps stack is also black. The black icon on the black titlebar looks ugly, especially next to white text. Here is a screenshot to help explain: Ugly color combination

Is it possible to specify a different icon for the launcher and task switcher?

EDIT: I see that Chrome does this: it changes it's task switcher icon to the current site's favicon, so unless that API is private, I know categorically this is possible.

like image 206
Timestretch Avatar asked Feb 13 '16 18:02

Timestretch


1 Answers

Yes, starting from API 21 forward, we have an option to customize our app's representation in the Recent Apps screen using the TaskDescription API.

If you only care about the icon, you can use this snippet below essentially anywhere from within an 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                    
          )  
      }

However, you have to keep in mind that your app's presentation on the Recent Apps screen is determined by the last TaskDescription you set.

As quoted from Big Nerd Ranch's awesome article on this matter:

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.

Hence to achieve the best result possible, you would want to put that snippet within your app's MainActivity's onCreate(..) method.

like image 168
Hadi Satrio Avatar answered Oct 22 '22 17:10

Hadi Satrio