Android Lollipop recents/multitasking header styli

2019-02-04 15:13发布

问题:

It seems switching between Theme.AppCompat.Light.DarkActionBar and Theme.AppCompat.Light has no effect on the text color and "close" button inside the recents menu. colorPrimary changes the header color, but the text and button are always black. Any ideas?

回答1:

For as far as I can tell you cannot change the color of the label text and close button because it is automatically set by the system. The only things that you can control are the icon, bar color, and label text via:

Activity.setTaskDescription(new ActivityManager.TaskDescription(label, icon, color));

You can test and see how the system automatically chooses the label and close button colors by supplying a dark or light color to the above function (i.e. set it to black, the text will be white and vice versa).

Docs: https://developer.android.com/about/versions/android-5.0.html#Recents
Javadocs: https://developer.android.com/reference/android/app/Activity.html#setTaskDescription(android.app.ActivityManager.TaskDescription)

-- EDIT -- Here's more details on how the platform determines the text color for the tasks.

The SystemUI app shows the recent task UI. It has a Task model Task.java:156 which detects if the contrast between your colorPrimary (specified in the task description) and white is above 3 it will use the light color. See Utilities.java:119 on how the contrast computation is done.

The text colors used for light and dark can be found here in SystemUI's colors.xml.



回答2:

r0adkll's answer is correct in that using Activity.setTaskDescription() gives you control over the background color, the icon (which should be square or else it is stretched) and the label. If you don't call Activity.setTaskDescription() at all though, and let the system style the Recents header itself, it will do the following:

  • The icon will be the activity's icon as set by android:icon in the manifest (not android:logo)
  • The label will be the activity's label as set by android:label in the manifest
  • The background color will be the theme's android:colorPrimary

The label (and close button) color will be light or dark depending on how dark or light the background is. There is no way to change the typeface of the label.