4

Device

Nexus 6 running 6.0.1.

Context

I have an app in which the Toolbar and content areas share a background color:

enter image description here

If I hit the 'recents' button, this color matching is preserved in the recents UI for my app:

enter image description here

If I select another app (in this example, the Project Fi app) from my recents screen, then hit the 'recents' button again, this color matching is no longer preserved:

enter image description here

This appears to happen regardless of:

  1. whether or not I explicitly apply a TaskDescription using Activity.setTaskDescription;
  2. whether I use the window or the root RelativeLayout to set the background color of the content area.

On Nougat, the color matching is preserved at all times on the recents screen (Nexus 6 running 7.0):

enter image description here

Questions

  • Is this expected behavior?
  • Is there a way to keep these colors matching on Marshmallow?

Relevant Files

build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.0"

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 24
        //...
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:24.0.0'
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.github.stkent.recenttaskuicolortest">

    <application
        ...
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

styles.xml

<resources>

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:windowBackground">@color/colorPrimary</item>
    </style>

</resources>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="@dimen/activity_margin">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/toolbar"
        android:text="Hello World!"
        android:textColor="@android:color/white" />

</RelativeLayout>

MainActivity.java, version 1

package com.github.stkent.recenttaskuicolortest;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setTitle(R.string.app_name);
    }

}

MainActivity.java, version 2

package com.github.stkent.recenttaskuicolortest;

import android.app.ActivityManager;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setTitle(R.string.app_name);

        updateRecentTasksUi();
    }

    @Override
    protected void onResume() {
        super.onResume();
        updateRecentTasksUi();
    }

    @Override
    protected void onPause() {
        updateRecentTasksUi();
        super.onPause();
    }

    private void updateRecentTasksUi() {
        final ActivityManager.TaskDescription taskDescription =
                new ActivityManager.TaskDescription(
                        getString(R.string.app_name),
                        null,
                        ContextCompat.getColor(this, R.color.colorPrimary));

        setTaskDescription(taskDescription);
    }

}
stkent
  • 19,772
  • 14
  • 85
  • 111
  • 1
    I don't know what is expected behavior here. Have you tried using an eyedropper tool somewhere to check the different colors? By eyeball, it would appear that the `Toolbar` color is staying stable and the content area is being faded. It's possible that the overview screen specifically applies some filter to the content area, perhaps as part of the "stack of cards" metaphor, though I don't know why they wouldn't just apply it to the whole UI. – CommonsWare Jul 19 '16 at 12:22
  • Yes, by comparing color codes it would definitely appear that the `Toolbar` color is the same in both cases (albeit ever so slightly darkened by the shadow effect that is applied to entire cards further back in the 'stack'), and the content area color is what's changing above and beyond that shadow effect. – stkent Jul 19 '16 at 12:37
  • Other than filing a bug report and seeing what shakes out, I can't see what you could do here. Even if you tweaked your color so that post-fade it is correct, then it will be too dark when your task is on the top of the overview stack. I don't know of any way to tell Android not to fade the task when it is not top-most on the overview screen, though I can't rule out some way to do that. – CommonsWare Jul 19 '16 at 12:42
  • Thanks for taking a look; I'll file that bug and see what happens! – stkent Jul 19 '16 at 12:57
  • Filed here: https://code.google.com/p/android/issues/detail?id=216483 – stkent Jul 19 '16 at 13:11

0 Answers0