Reputation: 1397
I have a strange probleme and i think it has something to do with the theme.
I structure my App in three parts: dashboard activity, list activity and detail activity. Each activity has the same theme. But after resuming from activity three is my Toolbar transparent and lost his primarycolor.
I can avoid this by copy the theme and rename it.
Has someone a solution for this?
<style name="TransAppTheme" parent="AppTheme">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
</style>
<style name="AppTheme" parent="AppTheme.Base"/>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:textColorPrimary">@color/text_primary</item>
<item name="android:textColorSecondary">@color/text_secondary</item>
<item name="colorPrimary">@color/dukes_blue_dark</item>
<item name="colorPrimaryDark">@color/dukes_blue_statusbar</item>
<item name="colorAccent">@color/accent_amber_200</item>
<item name="colorButtonNormal">@color/dukes_blue_dark</item>
<item name="colorControlNormal">@color/dukes_blue_dark</item>
<item name="colorControlActivated">@color/dukes_blue_dark</item>
</style>
Upvotes: 1
Views: 198
Reputation: 34532
Yes i animate my toolbar. Fading to transparent during scroll. But i don't reuse the same instance of Toolbar during my list and detail activity
The reason for this behavior lies within animating the toolbars drawable, I had the same issue.
Due to the toolbars using the same style / theme, the color drawable of the toolbar gets cached. Modifying the toolbars color (animating it) will cause this cached color drawable instance to change and remain changed. The style is invalid, the color transparent, and this will also affect your parent activtiies. This is as much as I figured out.
You can easily change this by using a different drawable for your animated toolbar:
// mToolbar is the toolbar you are trying to animate
final int color = ContextCompat.getColor(background.getContext(), R.color.primary);
if (Build.VERSION.SDK_INT > 15) {
mToolbar.setBackground(new ColorDrawable(color));
} else {
//noinspection deprecation
mToolbar.setBackgroundDrawable(new ColorDrawable(color));
}
This will stop your animated version to reuse the same drawable and affecting your other activities.
Upvotes: 2