问题描述
TextInputLayout boxBackgroundColor不适用于Alpha通道.当我将应用程序合并到AndroidX时发生了这种情况.合并之前,一切工作正常.
TextInputLayout boxBackgroundColor not apply alpha channel. This happened when I merge app to AndroidX. Before merging everything was working good.
当boxBackgroundColor为#77ff0000"时,当我将boxBackgroundColor设置为透明时,颜色显示为浅红色,颜色则显示为白色.它像先填充白色一样绘制背景,然后应用给定的boxBackgroundColor.
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.
等级:
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'com.google.android.material:material:1.1.0-alpha02'
推荐答案
您需要在主题中设置colorSurface
.它必须与基础布局的背景色匹配,否则您可能会得到其他一些奇怪的颜色. TextInputLayout
在内部组合colorSurface
和boxBackgroundColor
.
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
.
来源:TextInputLayout#calculateBoxBackgroundColor()
解决问题的示例:
<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>
这篇关于TextInputLayout FilledBox boxBackgroundColor不适用于Alpha通道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!