Attribute to customize Bounding box stroke
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?
I should mention that while this defaultStrokeColor looks alright on when using light backgrounds, it looks terrible with dark ones.
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>
Bad approach, @petrkubac we may want to use themes. Attributes are a better alternative.
@RowlandOti I have updated my post to make it more understandable what I was talking about. You can still use themes, but if you need to change the default box stroke colour now (until the issue is resolved), you can override it like I did.
Cool. Thanks for clarifying, it's currently the solution I was using, as it seems to be the only alternative at the moment. It is quite unsatisfactory, hence I look forward to a fix from the team.
@afohrman any updates for this issue as i have more than one theme and in each one i want deferent default color for the box stroke
What is status of this issue?
We are aware of this issue and we plan to add a defaultBoxStrokeColor (or similarly named) attribute so that this value can be parameterized. We plan to do this after we finish the color system, but we'd be happy to accept a pull request for this if anyone would like to contribute.
~petrkubac , what if we want to have two different TextInputLayouts depending on a theme. How can we use mtrl_textinput_default_box_stroke_color to set two different colours. TextInputLayout should be the very foundation of UI controls. Please provide a solution. Also it would be great if two other colours are attributes - mtrl_textinput_hovered_box_stroke_color and mtrl_textinput_disabled_color
Hi, @selena775 I don't think it is possible to do that without attributes that we can override in themes. The PR #181 could have helped, but I don't think it has been merged yet.
@RowlandOti, in my opinion every color and every text style should be configurable. That way the component is reusable, easily customisable and it will make developers life much easier. It is not only the stroke color that is a problem here, it is also primaryColor used as text color and one cannot change it easily. I would be very grateful if you make TextInputLayout completely configurable. Thank you so much for reading this comment and maybe land my wish.
Hi all, I am writing to show my displeasure while figuring out the coloring of this element and hopefully someone will take a look at it.
Is there anything against using color state lists? Shouldn't it be possible to just give a statelist for the floating label, or the border, or the background, or whatever? Like all other Android components have? I have to override now mtrl_textinput_disabled_color, mtrl_textinput_default_box_stroke_color so I can follow a design for those colors when I disable the element, I have to access defaultStrokeColor through reflection, I have to call setBoxBackgroundColorResource manually when I enable/disable the view... This is very ugly in the code and also it was very time consuming to figure it all out. It is not my style to put hacky stuff into a production app, but there is no other way here (if I want to use official components)
Hello everyone, as of the most recent version released (1.1.0-alpha02, although I believe it was available by alpha01) it is possible to use a color state list to change the stroke color of outlined text fields (through the boxStrokeColor attribute). (We currently use this color state list https://github.com/material-components/material-components-android/blob/master/lib/java/com/google/android/material/textfield/res/color/mtrl_box_stroke_color.xml)
There are also different attributes for text/hint/helper texts colors and appearances (https://github.com/material-components/material-components-android/blob/master/lib/java/com/google/android/material/textfield/res/values/styles.xml) and we are continuing the work to make text input layouts more configurable.
@leticiarossi thanks for the info! I shall check the alpha version then.
Thank you for the update -- I was able to successfully change the stroke colors for every state. 😄
I have same issue. How can to do that? @Corsage @joost-klitsie
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>
I suffered a lot today and my suggestion would be to make defaultStrokeColor public like the other. This is not intuitive and dark theme looks really bad (of course stateList works, but it is not a 'perfect' solution).

Can you post your code that resulted in the outline being that color in your dark theme? It shouldn't look like that by default so I'm just trying to understand what customizations are being made.
I think it was a bug that got fixed on one of the alphas, because I just tested on alpha04 and it is working as intended (just not in 1.0.0).