2

I have a main activity qual touching default colors AppBar color is brown, but I want a secondary activity that the bar is green and one yellow. So that each activity has a different color.

This is what I've tried:

It applies to all activities

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
</style>

I wanted applies only to one but not how it works

<style name="CapAlumnes" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/botoAlumnes</item>
    <item name="colorPrimaryDark">@color/botoAlumnes</item>
</style>

This is what I get:

enter image description here

Pierre.Vriens
  • 2,117
  • 75
  • 29
  • 42
Maria P
  • 21
  • 2
  • Possible duplicate of [Apply a theme to an activity in Android?](http://stackoverflow.com/questions/19125163/apply-a-theme-to-an-activity-in-android) – Bonatti May 18 '16 at 20:39
  • 1
    Set a different theme in Android Manifest for each activity – Vucko May 18 '16 at 20:42

3 Answers3

2

Create different themes in styles with different primary and secondary colors. Set each one of these themes to your individual activities in the Android manifest file.

<activity name="xyz" theme="styles/    mythemeColorGreen />

<activity name="xyd" theme="styles/     mythemeColorBlue />
0

In the Activity onCreate:

mToolbar.setBackgroundDrawable(new ColorDrawable(getResources()
            .getColor(R.color.botoAlumnes)));

If APK >= 16

mToolbar.setBackground(new ColorDrawable(getResources()
                .getColor(R.color.botoAlumnes)));
Syrius
  • 1
  • 4
0

You can always just use the android:background attribute in your XML layouts.

Karakuri
  • 38,365
  • 12
  • 84
  • 104
  • If all you need is to change the background, you are correct. However, `colorPrimary` and `colorPrimaryDark` do more than that, so if you need all the effects of changing these items, (like changing the color of the status bar) using themes is the correct answer. – Soren Stoutner Jun 09 '16 at 17:25