In design library source we can find this line:
<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>
I want to change the color of the error text through errorTextAppearance attribut
I know how to customize it through app:{atribut-name} in the TextInputLayout xml declaration but how can I get to customize one of this attribut from within my theme definition ?
To make it simpler, you have a custom view that holds a set of attributes. To provide values there are three different ways from the bottom (view) to top (application)
style="@style/MyStyle"defStyleAttrparameter of the constructor of your custom view. And assign a style to this attribute in your theme and Voila!!For the first two, it is straight forward. Let's concentrate on the last method. There are four steps to achieve this
Step 1
Create an attribute (generally in
res/values/attrs.xmlfileStep 2
Using this newly created attribute inside your custom view.
Assuming your custom view's class name is
MyCustomView. Your class's constructor will look something like thisThis will enforce
MyCustomViewto use attributes frommyCustomViewAttrif nothing is provided for the attributes in the layout.Step 3
Create a style, which is the easiest and used by most of them
In case, you want to assign some other attribute to your
errorTextAppearance, thenStep 4
Last and final step, assign the style to the attribute
If your text appearance comes from some other attribute, then you can directly assign the attribute