cprcrack
cprcrack

Reputation: 19179

In Android styles.xml, how to reference another style attribute from my custom style?

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?

Upvotes: 6

Views: 1620

Answers (1)

Layne Qi
Layne Qi

Reputation: 1

<ImageView
    android:theme="@style/TextAppearance.Compat.Notification.Title"
    android:tint="?android:textColor" />

Upvotes: 0

Related Questions