How to change material TextInputLayout OutlinedBox unfocused Color

喜你入骨 提交于 2019-12-03 10:14:54

问题


I have an OutlinedBox TextInputLayout and I want to change the box color in the unfocused mode of editText.

How can I do that?


回答1:


In the theme Add colorOnSurface attribute and assign any color you want

<style name="Apptheme"
       parent="Theme.MaterialComponents.Light.NoActionBar">
    <!-- General theme colors -->
    <item name="colorPrimary">@color/material_green_500</item>
    <item name="colorSecondary">@color/material_green_600</item>
    <item name="colorAccent">@color/illiniColorAccent</item>

    <item name="colorOnSurface">@color/blue</item><!--inputtext unfocused color-->
</style>

The result is: Also colorPrimary is the color of focused state.

Other attributes you can customize are:

<item name="enforceMaterialTheme">true</item>
<item name="enforceTextAppearance">true</item>

<item name="boxBackgroundMode">outline</item>
<item name="boxBackgroundColor">@null</item>
<item name="endIconTint">@color/mtrl_outline_end_icon_tint</item>
<item name="boxCollapsedPaddingTop">0dp</item>
<item name="boxCornerRadiusTopStart">@dimen/mtrl_textinput_box_corner_radius_medium</item>
<item name="boxCornerRadiusTopEnd">@dimen/mtrl_textinput_box_corner_radius_medium</item>
<item name="boxCornerRadiusBottomEnd">@dimen/mtrl_textinput_box_corner_radius_medium</item>
<item name="boxCornerRadiusBottomStart">@dimen/mtrl_textinput_box_corner_radius_medium</item>
<item name="boxStrokeColor">@color/mtrl_outlined_stroke_color</item>

<item name="counterTextAppearance">?attr/textAppearanceCaption</item>
<item name="counterOverflowTextAppearance">?attr/textAppearanceCaption</item>
<item name="errorTextAppearance">?attr/textAppearanceCaption</item>
<item name="helperTextTextAppearance">?attr/textAppearanceCaption</item>
<item name="hintTextAppearance">?attr/textAppearanceCaption</item>

<item name="counterTextColor">@color/mtrl_indicator_text_color</item>
<item name="counterOverflowTextColor">@color/mtrl_error</item>
<item name="errorTextColor">@color/mtrl_error</item>
<item name="helperTextTextColor">@color/mtrl_indicator_text_color</item>
<!-- The color of the label when it is collapsed and the text field is active -->
<item name="hintTextColor">?attr/colorPrimary</item>
<!-- The color of the label in all other text field states (such as resting and disabled) -->
<item name="android:textColorHint">@color/mtrl_indicator_text_color</item>

<item name="shapeAppearance">?attr/shapeAppearanceSmallComponent</item>
<item name="shapeAppearanceOverlay">@null</item>


来源:https://stackoverflow.com/questions/55357407/how-to-change-material-textinputlayout-outlinedbox-unfocused-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!