question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[TextInputLayout] boxStrokeColor doesn't work with ColorStateLists for a variety of states.

See original GitHub issue

Description: According to the documentation we can change the box color of a TextInputLayout using the attribute boxStrokeColor.

in truth, unless this is defined as a color selector, this only alter the focused color. It looks usually ok on white background but it’s really bad in dark background.

Instead the focused color change and the non focused color stay the default, which is

  • default = mtrl_textinput_default_box_stroke_color
  • disabled = mtrl_textinput_disabled_color
  • hovered = mtrl_textinput_hovered_box_stroke_color

Expected behavior: the boxStrokeColor should be taken and be used to generate defaultStrokeColor, focusedStrokeColor, hoveredStrokeColor and disabledColor according to https://material.io/design/interaction/states.html#anatomy

Source code:

<com.google.android.material.textfield.TextInputLayout
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:boxStrokeColor="#FFF"/>

Android API version: Any. We tried on P, Q.

Material Library version: 1.1.0-alpha10

Device: Pixel 2, Pixel 3

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:17
  • Comments:25 (5 by maintainers)

github_iconTop GitHub Comments

12reactions
zishanjcommented, Sep 24, 2019

Just overriding the mtrl_textinput_default_box_stroke_color value fixed it:

<color name="mtrl_textinput_default_box_stroke_color" tools:override="true">#aaaaaa</color>

11reactions
danielesegatocommented, Sep 25, 2019

Just overriding the mtrl_textinput_default_box_stroke_color value fixed it:

<color name="mtrl_textinput_default_box_stroke_color" tools:override="true">#aaaaaa</color>

This is really a BAD idea.

mtrl_textinput_default_box_stroke_color is not used only there.

If you want to change the color right now create a color selector and use it to set the color:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="true" android:color="@color/stroke_enabled"/>
    <item android:state_hovered="true" android:color="@color/stroke_hovered"/>
    <item android:state_focused="true" android:color="@color/stroke_focused"/>
    <item android:color="@color/stroke_default"/>
</selector>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Change the TextInputLayout outline color - Stack Overflow
There are various ways to change TextInputLayout box stroke color and hint text color. The responsible attribute for box outline color is ...
Read more >
TextInputLayout | Android Developers
Returns the text color used for the character counter, or null if one has not been set. ColorStateList, getDefaultHintTextColor(). Returns the ...
Read more >
How To Change Bottom Line Color And Hint - ADocLib
I am using android design library's TextinputLayout.But couldn't customize the hint color label color and the underline color of EditText inside.
Read more >
android.content.res.ColorStateList#isStateful
Source Project: material-components-android File: TextInputLayout.java License: ... getDefaultColor()) { // If attribute boxStrokeColor is not a color state ...
Read more >
CardNumberTextInputLayout - Stripe Developer Resources
CardNumberTextInputLayout. @RestrictTo(value = [RestrictTo.Scope.LIBRARY_GROUP]). class CardNumberTextInputLayout : TextInputLayout. An TextInputLayout that ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found