具有轮廓但透明背景的TextInputLayout

时间:2019-12-27 09:15:28

标签: android android-textinputlayout

如果boxBackgroundColor是透明的,则boxStroke不可见

<style name="OutlinedRoundedBox" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
    <item name="boxBackgroundColor">@android:color/transparent</item>
    <item name="boxStrokeColor">@android:color/white</item>
    <item name="boxStrokeWidth">4dp</item>
</style>

那么只有使用自定义背景才能有透明的TextInputLayout而没有轮廓吗?

例如:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item>
        <shape android:shape="rectangle">

            <corners android:radius="5dp" />

            <stroke
                android:width="2dp"
                android:color="@color/colorEditTextOutline" />

        </shape>
    </item>

</layer-list>

1 个答案:

答案 0 :(得分:2)

如果您发布了一个设计,那么它会更容易理解。对于此解决方案如果我对您的理解正确,则需要添加这两件事

在样式中添加:

<style name="InputLayoutStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
    <item name="boxStrokeColor">@color/text_input_box</item>
</style>

添加颜色资源:

<?xml version="1.0" encoding="utf-8"?>   
  <selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="@color/red_bright" android:state_focused="true" />
    <item android:color="@color/red_bright" android:state_hovered="true" />
    <item android:color="@color/red_bright" />
  </selector>

如果这是您想要的,此解决方案将具有以下内容 this is the design whig has whiteBG