Nexus 6正在运行6.0.1。
我有一个应用,其中Toolbar
和内容区域共享背景颜色:
如果我点击了'按钮,此颜色匹配保留在我的应用的最近用户界面中:
如果我从我的最近屏幕中选择了另一个应用程序(在此示例中为Project Fi应用程序),那么请点击“最近”按钮'再次按钮,此颜色匹配不再保留:
这似乎发生在以下情况:
TaskDescription
; Activity.setTaskDescription
RelativeLayout
来设置内容区域的背景颜色。在Nougat上,颜色匹配始终保留在最近的屏幕上(运行7.0的Nexus 6):
的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);
}
}