5

I have the following style defined in styles.xml:

<style name="NotificationTitle"
    parent="android:TextAppearance.Material.Notification.Title" />

Which as you see extends the following default style defined in Android:

<style name="TextAppearance.Material.Notification.Title">
    <item name="textColor">@color/notification_primary_text_color_light</item>
    <item name="textSize">@dimen/notification_title_text_size</item>
</style>

Now, back to my styles.xml file, I would like to create the following custom style with its "android:tint" attribute set to the same value as the "textColor" defined in the parent style. I have tried something like this:

<style name="NotificationIcon" >
    <item name="android:tint">@style/NotificationTitle.textColor</item>
</style>

However I cannot reference "textColor" like that, it cannot resolve the symbol. So how can I reference another attribute defined in another style from my custom style? If not possible, what would be the best alternative?

cprcrack
  • 17,118
  • 7
  • 88
  • 91
  • Why don't you use colors.xml and refer the color in both places from there? – Nabin Bhandari Oct 02 '17 at 04:51
  • @NabinBhandari Because I don't know the color, it changes from device to device, and I cannot reference `@color/notification_primary_text_color_light` because it's not public and the name could change in the future, so it's not safe anyways. – cprcrack Oct 02 '17 at 05:02
  • I was able to do it programmatically using this solution: https://stackoverflow.com/a/25457076/423171 In any case I would prefer to do it via styles.xml – cprcrack Oct 02 '17 at 05:04

0 Answers0