如何设置TextInputlayout的概述框浮动提示背景颜色

问题描述 投票:0回答:3

如何在文本输入布局轮廓框样式中更改浮动提示的背景颜色为透明。我认为附带的图片清楚地表明了它应该在中风上方红色,下面是白色)。我为改变背景本身所做的是:

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

Outlined box with corrupted background

任何帮助都非常感谢

android background android-edittext material-design android-textinputlayout
3个回答
5
投票
如果您在

https://material.io/develop/android/components/components/text-fields/中查看样式文档“没有。

因此,除非您在布局中找到内部提示并手动更改背景,否则我认为该问题没有适当的解决方案。但这将是相当骇人听闻的,因为这取决于
boxBackgroundColor

保持相同的实现。

我不知道它是否有帮助,但是我设法在
outline box模式的thetextinputlayout
框架内的盒子中都有统一的背景。


1
投票

在我的示例中,盒子拐角具有10DP半径(TextView

)。另外,

TextInputEditText具有80dp(enter image description hereTextInputLayout)的高度。

I为TextInputlayout定义了我应用自定义背景形状的样式:

text_input_layout_box_radius
可绘制的绘制定义为层列表:
text_input_edit_text_height

<style name="MyTextInputLayout" parent="Widget.Design.TextInputLayout"> <item name="android:background">@drawable/text_input_background</item> <!-- ... other customizations ... --> </style>

等于13dp,在这里可以做到魔术。就我而言,它以盒子内的形状为中心。在我的情况下,需要补偿30SP的提示高度,可以使用
text_input_background.xml
属性进行修改。您可能必须找到与提示文本高度相对应的正确填充值。

让我知道它是否有帮助!

    

为提示而设置单独的背景颜色感觉有些怪异,并且看起来不像是正式支持的东西,但是Sethint()方法采用char squence参数 - 也许您可以尝试使用BackgroundColorspan的spannabestring。
我尝试过,对我有用:)

旅行更新您的材料组件gradle
'com.google.android.material:材料:1.4.0'

I更新此版本并解决了我的问题


0
投票

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.