6

I'm dealing with Android L color definitions to define the rows of a ListView. I have a theme which has:

    <item name="colorAccent">@color/color_blue_dark</item>

and in my row I've defined another one:

<style name="DefaultRow">
    <item name="colorAccent">@color/color_sand</item>
    <item name="android:background">?android:attr/activatedBackgroundIndicator</item>
</style>

Assuming that colorAccent value will be overriden. but that doesn't if I do in my row:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
          ...
          style="@style/DefaultRow"/>

enter image description here

But it works if I do:

 <TextView xmlns:android="http://schemas.android.com/apk/res/android"
              ...
              android:theme="@style/DefaultRow"/>

enter image description here

What's the difference? is colorAccent being defined when the theme is applied and not overriden later? How to solve this to have retrocompatibility?

Guillermo Merino
  • 3,197
  • 2
  • 17
  • 34
  • 2
    Read https://chris.banes.me/2014/11/12/theme-vs-style/ – alanv Aug 06 '15 at 17:51
  • thanks for the comment, but I'm still not clear about why is this happening, as far as I understand, styles are applied locally to the view and themes to it's descendants. But why is this changing the behaviour on the view itself where it is being applied? – Guillermo Merino Aug 07 '15 at 09:28
  • 1
    The `android:theme` attribute is applied to the view itself as well as its descendants. Internally, it creates a `ContextThemeWrapper` and inflates the view and its descendants against that context. – alanv Aug 07 '15 at 15:44

1 Answers1

0

TextView doesn't have a colorAccent property. It is a theme property.

Jorgesys
  • 124,308
  • 23
  • 334
  • 268
Daniel Luberda
  • 7,374
  • 1
  • 32
  • 40
  • Actually, it does, I'm using ?android:attr/activatedBackgroundIndicator as an attribute for the background and checking http://stackoverflow.com/questions/15008150/how-does-androidattr-activatedbackgroundindicator-work this answer I assume that it's using colorAccent in the back – Guillermo Merino Aug 07 '15 at 08:17
  • But it's still a theme property, not style property. This is why it won't work with styles. It's Android 5 and above only feature – Daniel Luberda Aug 07 '15 at 11:47