Search code examples
androidbackgroundandroid-edittextmaterial-designandroid-textinputlayout

How to set TextInputLayout's outlined box floating hint background color


How to change the background color of the floating hint in a text input layout outline box style to transparent. I think the attached picture clearly states the issue It should be red above the stroke and white below). What I did to change the background itself was:

<style name="App.TextInputLayout" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
    <item name="boxBackgroundColor">@color/white</item>
</style>

Outlined box with corrupted background

Any help is greatly appreciated


Solution

  • If you look at the style docs in https://material.io/develop/android/components/text-fields/ you can see the "Filled text view" supports the boxBackgroundColor attribute while the "Outlined text field" does not.

    So I don't think there's a proper solution to this problem unless you find the inner hint TextView within the layout and change the background manually. But that would be quite hacky since it depends on the implementation of the TextInputLayout staying the same.