How to declare several stylable attributes with the same name for different tags?

The link you have posted does give you the correct answer. This is what it suggests you do:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <attr name="title" format="string" />
    <declare-styleable name="ViewA">
        <attr name="title" />
    </declare-styleable>
    <declare-styleable name="ViewB">
        <attr name="title" />
        <attr name="max" format="integer" />
    </declare-styleable>
</resources>

Now, R.styleable.ViewA_titleand R.styleable.ViewB_titleare both accessible.

If you get a chance, read through this answer: Link. Relevant quote:

You can define attributes in the top element or inside of
a element. If I’m going to use an attr in more
than one place I put it in the root element.

Leave a Comment

File not found.