【问题标题】:Different color of TextInputLayout outline color when enable=true then black and enable false than light gray当 enable=true 时 TextInputLayout 轮廓颜色的颜色不同,然后是黑色,启用 false 时比浅灰色
【发布时间】:2019-09-19 18:55:27
【问题描述】:

我正在使用TextInputLayout,根据我们的需要,我想更改enable=true时的轮廓颜色和enable=false时的灰色颜色

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

【问题讨论】:

    标签: android material-design android-textinputlayout material-components-android material-components


    【解决方案1】:

    在Material Component Library 中使用TextInputLayout 并在您的布局中使用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>
    

    【讨论】:

      猜你喜欢
      • 2018-11-21
      • 1970-01-01
      • 2021-06-21
      • 2017-10-29
      • 2020-06-19
      • 2021-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多