当enable = true时为黑色,而为false时,TextInputLayout轮廓颜色的颜色与浅灰色不同

时间:2019-05-01 06:15:40

标签: android android-textinputlayout

我正在使用TextInputLayout,根据需要,我想在 enable=true 时更改轮廓颜色,而在 enable=false时更改灰色颜色< / strong>

 <android.support.design.widget.TextInputLayout
            android:id="@+id/state_text_input"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:layout_marginTop="24dp"
            android:layout_marginRight="8dp">

1 个答案:

答案 0 :(得分:0)

使用TextInputLayout中的Material Component Library,并在布局中使用 app:boxStrokeColor 属性。

类似的东西:

<com.google.android.material.textfield.TextInputLayout
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
    app:boxStrokeColor="@color/text_input_layout_stroke_color"
    ...>

您可以使用选择器。它是默认值:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:color="?attr/colorPrimary" android:state_focused="true"/>
  <item android:alpha="0.87" android:color="?attr/colorOnSurface" android:state_hovered="true"/>
  <item android:alpha="0.12" android:color="?attr/colorOnSurface" android:state_enabled="false"/>
  <item android:alpha="0.38" android:color="?attr/colorOnSurface"/>
</selector>