TextInputLayout FilledBox boxBackgroundColor not apply alpha channel

风格不统一 提交于 2020-06-16 21:18:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!