Search code examples
androidmaterial-designandroid-textinputlayoutmaterial-components-androidmaterial-components

Change the style for all the TextInputLayout (in the theme)


I've defined an specific TextInputLayout style, modifing the Widget.MaterialComponents.TextInputLayout.OutlinedBox

    <style name="TextInput" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
        <item name="boxBackgroundMode">outline</item>
        <item name="boxBackgroundColor">@color/inputBackground</item>
        <item name="boxCollapsedPaddingTop">12dp</item>
    </style>

Now I want to apply this style to all the TextInputLayouts. I can add the style to all the textInputLayouts, but, can I add it to my theme as the default style? How?

Thanks


Solution

  • Just override the textInputStyle attribute in your app theme:

    <style name="AppTheme" parent="Theme.MaterialComponents.Light">
    
      <item name="textInputStyle">@style/TextInput</item>
    
      <!-- Default value is: <item name="textInputStyle">@style/Widget.MaterialComponents.TextInputLayout.FilledBox</item> -->
    </style>