1

I want to change some colors of android UI elements. But I would prefer to set a default tint color, which applies to all UI elements. I am not sure if this is possible. If not, I want to set the "tint"-color of some UI elements, as shown below. Can anybody enlighten me?

colors of text and dividers in datepicker

highlight colors of buttons

enabled color of switch

progress color of seekbar

EDIT

Based on what Entreco suggested:

My styles.xml:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="android:textColorPrimary">@color/brown</item>
        <item name="android:textColorSecondary">@color/brown</item>
        <item name="android:textColorTertiary">@color/brown</item>
        <item name="android:textColorPrimaryInverse">@color/brown</item>
        <item name="android:textColorSecondaryInverse">@color/brown</item>
        <item name="android:textColorTertiaryInverse">@color/brown</item>

        <item name="colorPrimary">@color/blue</item>
        <item name="colorPrimaryDark">@color/blue</item>

        <item name="android:actionBarStyle">@style/MyActionBar</item>
        <item name="actionBarStyle">@style/MyActionBar</item>

    </style>
    <!-- style for the action bar backgrounds -->
    <style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar">
        <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
        <item name="android:subtitleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
        <item name="android:background">@color/brown</item>
        <item name="titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
        <item name="subtitleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
        <item name="background">@color/brown</item>
    </style>
    <style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance">
        <item name="android:textColor">@color/brown_light</item>
        <item name="android:textSize">24sp</item>
    </style>

</resources>

And my values-v21/styles.xml:

<resources>
    <style name="AppTheme" parent="AppTheme.Base">
        <item name="android:colorPrimary">@color/blue</item>
        <item name="android:colorPrimaryDark">@color/blue</item>
        <!-- <item name="android:colorAccent">@color/white</item> -->
    </style>
</resources>

And in my Manifest:

<application android:theme="@style/AppTheme.Base" >
    ...
</application>

But the primary color is still the same...???

gotwo
  • 663
  • 8
  • 16
mrd
  • 4,561
  • 10
  • 54
  • 92
  • there is no easy way(for API < 21): 1,2 Custom dialog 3. custom drawabable as button's background 4. custom drawable ... 5. support v7 6. custom ... – Selvin Mar 09 '15 at 13:53
  • if you want to change each view attributes individually, you have to set a theme (not style) for them in XML layout. for example, just add `android: theme="@style/yourThemeHere"` – Kapta Feb 21 '20 at 09:15

1 Answers1

0

Starting from Lollipop this is straight-forward thanks to the colorPrimary attribute:

file values/styles.xml:

<!-- Base application theme. -->
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
</style>

file values-v21/styles.xml:

<style name="AppTheme" parent="AppTheme.Base">
    <item name="android:colorPrimary">@color/primary</item>
    <item name="android:colorPrimaryDark">@color/primary_dark</item>
    <item name="android:colorAccent">@color/white</item>
</style>

Basically, you can define a color pallete for your app, and I believe for your case your want to set the colorPrimary (unverified).

More info on Material colors

Entreco
  • 12,738
  • 8
  • 75
  • 95