customize Bounding box stroke in TextInputLayout.OutlinedBox

前端 未结 1 949
面向向阳花
面向向阳花 2021-01-03 08:25

I\'m trying to change box Stroke Color of com.google.android.material.textfield.TextInputLayout while not focused but there is no attribute for that this is my

相关标签:
1条回答
  • 2021-01-03 08:34

    To change the box stroke color just use the app:boxStrokeColor attribute in the xml.

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

    You should use a selector. It is the default:

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

    You can also use a custom style:

      <style name="MyOutlinedBox" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
        <item name="boxStrokeColor">@color/text_input_selector</item>
      </style>
    

    0 讨论(0)
提交回复
热议问题