问题
TextInputLayout boxBackgroundColor not apply alpha channel. This happened when I merge app to AndroidX. Before merging everything was working good.
When boxBackgroundColor is "#77ff0000" color appears as light red when I set boxBackgroundColor as transparent, color appears as white. It draws background like first fill with white color and then applies given boxBackgroundColor.
Gradle:
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'com.google.android.material:material:1.1.0-alpha02'
回答1:
You need to set colorSurface
in your theme. It must match the background color of underlying layout or you might get some other weird color. TextInputLayout
internally combines colorSurface
and boxBackgroundColor
.
Source: TextInputLayout#calculateBoxBackgroundColor()
Example how to fix the problem:
<style name="MyTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="textInputStyle">@style/MyTextInputLayout</item>
<item name="colorSurface">#FFFFFFF</item>
</style>
<style name="MyTextInputLayout" parent="@style/Widget.MaterialComponents.TextInputLayout.FilledBox">
<item name="boxBackgroundColor">#77FF0000</item>
</style>
来源:https://stackoverflow.com/questions/54002965/textinputlayout-filledbox-boxbackgroundcolor-not-apply-alpha-channel