具有轮廓但背景透明的 TextInputLayout

TextInputLayout with outline but transparent background

如果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>

如果您发布了它的设计,那么它会更容易理解。对于这个解决方案如果我理解正确的话,你需要添加这两个东西

在样式中添加:

<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>

如果这是你想要的,这个解决方案会有这样的东西