Получение атрибута внутри стилизованного через XML - PullRequest
0 голосов
/ 05 августа 2020

У меня есть несколько TextView в моем пользовательском представлении. И я хочу, чтобы они взяли стиль из темы. Для этого я обращаюсь к пользовательскому атрибуту labelTextAppearance:

<TextView
    ...
    android:textAppearance="?attr/labelTextAppearance" />

Если я объявляю labelTextAppearance на уровне темы, все работает замечательно:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="labelTextAppearance">@style/SavageWorldsTextAppearance.Label</item>
</style>

Но я хочу иметь возможность объявить стиль для всех пользовательских представлений с помощью одного свойства. Так же, как Button через butonStyle. Для этого я создал новый атрибут paramViewStyle, в котором перечислены мои textAppearance:

<style name="Widget.AppTheme.ParamView.Custom">
        <item name="valueTextAppearance">@style/SavageWorldsTextAppearance.DefaultValue</item>
        <item name="defaultValueTextAppearance">@style/SavageWorldsTextAppearance.DefaultValue</item>
        <item name="labelTextAppearance">@style/SavageWorldsTextAppearance.Label</item>
</style>

Затем я указываю paramViewStyle в теме приложения:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="paramViewStyle">@style/Widget.AppTheme.ParamView.Custom</item>
</style>

Но TextView не может догнать, что атрибуты теперь находятся в paramViewStyle.

Как я могу сообщить TextView через xml, что интересующие их параметры находятся внутри другого атрибута?

UPD : Это мои атрибуты уровня темы:

<declare-styleable name="ParamViewTheme">
    <!-- ParamsView default style. -->
    <attr name="paramViewStyle" format="reference"/>

    <attr name="valueTextAppearance" format="reference"/>
    <attr name="defaultValueTextAppearance" format="reference"/>
    <attr name="labelTextAppearance" format="reference"/>
</declare-styleable>
...