1

В источнике библиотеки дизайна можно найти такую ​​строку:Стиль пользовательского TextInputLayout attribut внутри темы

<declare-styleable name="TextInputLayout"> 
    <attr format="reference" name="hintTextAppearance"/> 
    <attr name="android:hint"/> 
    <attr format="boolean" name="errorEnabled"/> 
    <attr format="reference" name="errorTextAppearance"/> 
    <attr format="boolean" name="counterEnabled"/> 
    <attr format="integer" name="counterMaxLength"/> 
    <attr format="reference" name="counterTextAppearance"/> 
    <attr format="reference" name="counterOverflowTextAppearance"/> 
    <attr name="android:textColorHint"/> 
    <attr format="boolean" name="hintAnimationEnabled"/> 
</declare-styleable> 

Я хочу, чтобы изменить цвет текста ошибки через errorTextAppearance attribut

Я знаю, как настроить его через app: {atribut-name} в объявлении xml TextInputLayout, но как я могу настроить один из этих атрибутов из моего определения темы?

ответ

0

styles.xml:

<style name="TextInputLayout.Error" parent="@style/TextAppearance.Design.Error"> 
    <item name="android:textColor">@color/textinput_error_color</item> 
</style> 

<style name="Theme.AppName.TextInputLayout" parent="@style/Widget.Design.TextInputLayout"> 
    <item name="errorTextAppearance">@style/TextInputLayout.Error</item> 
</style> 

в макете:

<android.support.design.widget.TextInputLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       style="@style/Theme.AppName.TextInputLayout"> 

       ... 
      </android.support.design.widget.TextInputLayout> 

Также вы можете добавить другие элементы из Widget.Design.TextInputLayout в Theme.AppName.TextInputLayout

+0

Спасибо, что нашли время, чтобы ответить. :-) Когда я писал в теме, мне было интересно, как применить этот стиль, используя атрибут обобщения темы. (Без применения стиля или атрибута непосредственно в TextInputLayout.) – user40797