Inconsistent application colors on the Marshmallow regenerates screen

Device

Nexus 6 runs 6.0.1.

Context

I have an application in which areas Toolbarand content share a common background color:

enter image description here

If I click the "recents" button, this color matching is saved in the recents user interface for my application:

enter image description here

If I select another application (in this example, the Project Fi application) on the screen of my retentate, then click the "repeats" button again, this color matching will no longer be saved:

enter image description here

This happens regardless of:

  • Explicitly apply TaskDescriptionwith Activity.setTaskDescription;
  • I use a window or root RelativeLayoutto set the background color in the content area.

Nougat (Nexus 6 7.0):

enter image description here

  • ?
  • Marshmallow?

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, 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, 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);
    }

}
+4

Source: https://habr.com/ru/post/1648249/


All Articles