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.

Attribute to customize Bounding box stroke

See original GitHub issue

I can see that the bounding box for the TextInputLayout has been explicitly declared here:

 defaultStrokeColor =
        ContextCompat.getColor(context, R.color.mtrl_textinput_default_box_stroke_color);
    disabledColor = ContextCompat.getColor(context, R.color.mtrl_textinput_disabled_color);
    hoveredStrokeColor =
        ContextCompat.getColor(context, R.color.mtrl_textinput_hovered_box_stroke_color);

i.e :

https://github.com/material-components/material-components-android/blob/master/lib/java/com/google/android/material/textfield/TextInputLayout.java#L314

Are there plans to provide an attribute that allows developers, to for example override these? For example, use color states?

Issue Analytics

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

github_iconTop GitHub Comments

22reactions
petrkubaccommented, Jul 4, 2018

Because the defaultBoxStrokeColor is currently private final int in TextInputLayout class you can change it only by overriding the color resource it uses. This is a temporary solution if you need to change this color until the issue gets resolved.

<color name="mtrl_textinput_default_box_stroke_color" tools:override="true">@color/white_40</color>

18reactions
Corsagecommented, Feb 19, 2019

I believe I was able to do it with the following:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="@android:color/background_light" android:state_focused="true"/>
    <item android:color="@android:color/background_light" android:state_hovered="true"/>
    <item android:color="@android:color/background_light" android:state_enabled="false"/>
    <item android:color="@android:color/background_light" />
</selector>

Take a note of the different android states, and then lastly the default state. Change the colors accordingly to what you need and then you can use it as a theme, an example is shown below.

<!-- Hint text appearance (used only when the background is colorPrimary). -->
    <style name="TextInputLayoutWhiteBox" parent="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
        <item name="boxStrokeColor">@color/layout_text_input_white</item>
        <!-- The color of the label when it is collapsed and the text field is active -->
        <item name="hintTextColor">@android:color/background_light</item>
        <!-- The color of the label in all other text field states (such as resting and disabled) -->
        <item name="android:textColorHint">@android:color/background_light</item>
    </style>
Read more comments on GitHub >

github_iconTop Results From Across the Web

customize Bounding box stroke in TextInputLayout.OutlinedBox
To change the box stroke color just use the app:boxStrokeColor attribute in the xml. <com.google.android.material.textfield.
Read more >
Apply and adjust stroke properties – Figma Help Center
Custom : to choose which sides to apply stroke. Custom also allows you to set a different stroke weight per side. Tip! Rectangles...
Read more >
Proposals/Bounding boxes - SVG
In SVG 2, we add definitions for bounding boxes that include the stroke or even stroke plus markers (decorations). The Masking Module uses...
Read more >
Common wrap and stroke attributes - Sitecore Documentation
The table lists the common wrap and stroke attributes with their use, (default) value(s), and description. ... 3: Wrap around bounding box.
Read more >
transform-box - CSS: Cascading Style Sheets - MDN Web Docs
The stroke bounding box is used as the reference box. view-box. The nearest SVG viewport is used as the reference box. If a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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