Device
Nexus 6 running 6.0.1.
Context
I have an app in which the Toolbar
and content areas share a background color:
If I hit the 'recents' button, this color matching is preserved in the recents UI for my app:
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:
This appears to happen regardless of:
- whether or not I explicitly apply a
TaskDescription
usingActivity.setTaskDescription
; - 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):
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);
}
}