Android | Change theme of TextInputLayout using styles.xml
The solution I used in my project :
<style name="AppBaseTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="textInputStyle">@style/TextInputLayoutTheme</item>
</style>
<style name="TextInputLayoutTheme" parent="Widget.Design.TextInputLayout">
<item name="colorOnSurface">@android:color/transparent</item>
</style>
Unfortunately, the TextInputLayout
widget, and it seems all widgets in the Design Support Library, don't define a global theme attribute for it's default style. Therefore, it's not possible to customize it's style globally, other than by subclassing it to support a custom theme attribute to query the default style from, and using the subclass everywhere instead.
Note that the Widget.Design.TextInputLayout
style would still be hardcoded as the default style on which the widget would fall back to if it can't find the attribute defined in it's theme, so this would be no different than the existing implementation by default.
It seems that there is a misconception in the Design Support Library developers that defining a default theme attribute requires it to be present in the current theme in order to work properly. This issue was reported previously for TabLayout
, but was closed based on this reasoning, and subsequent queries and clarifications did not generate further response. Feel free to open another ticket on the AOSP issue tracker with the necessary clarification; hopefully it might fare better.