2

My problem is that I don't know how to change underline color of EditText - I have LG Nexus 5 (Android 6).

enter image description here

I would like to change normal underline color to white. I used all params like (style):

  • colorControlNormal
  • colorControlActivated
  • colorControlHighlight
  • textColorSecondary
  • colorPrimary
  • colorPrimaryDark

e.g.

<style name="FormFont" parent="@android:style/TextAppearance.Medium">
    <item name="android:textColor">@color/white</item>
    <item name="android:textSize">@dimen/form_text_size</item>
    <item name="colorControlNormal">#c5c5c5</item>
</style>

but nothing seems to work (it only changes color when EditText us focused like in above pic).

Adam Styrc
  • 1,517
  • 2
  • 23
  • 38

5 Answers5

1
<style name="Theme.App.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorControlNormal">#c5c5c5</item>
    <item name="colorControlActivated">@color/accent</item>
    <item name="colorControlHighlight">@color/accent</item>
</style>
Matias Elorriaga
  • 8,880
  • 5
  • 40
  • 58
  • I checked it - it's silly it works only when set in main AppTheme but not when set in different style like I did. What if I don't want to use the same color in every EditText of my app ? – Adam Styrc Mar 02 '16 at 20:17
  • I'm not sure if it's possible. I'll check it and make you know if I find something. – Recomer Mar 02 '16 at 20:20
  • 1
    You can make a separate style for your EditTexts and set the parent of that to `Theme.App.Base` and apply that to the EditTexts of your choice via `android:theme="@style/Theme.App.YourEditTextTheme"` in your XML layout – Mark Mar 02 '16 at 20:21
  • I think that your Theme must be a child of Theme.AppCompat.* – Matias Elorriaga Mar 02 '16 at 20:21
  • I found this [answer](http://stackoverflow.com/questions/4584882/how-to-change-focus-color-of-edittext-in-android/4585750#4585750). Basically what it says is you're going to create your background by using a NinePatch Image(you can create by using [this](https://romannurik.github.io/AndroidAssetStudio/nine-patches.html) one by Roman Nurik itself) and than build it as your new StateListDrawable. – Recomer Mar 02 '16 at 20:26
  • I wanted to avoid NinePatch but it might be the only answer – Adam Styrc Mar 03 '16 at 09:17
1

The most efficient thing to do is to add the colorAccent attribute in your AppTheme style like this:

<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">         

<item name="colorAccent">@color/colorAccent</item>    
<item name="android:editTextStyle">@style/EditTextStyle</item>
</style>
<style name="EditTextStyle" parent="Widget.AppCompat.EditText"/>

The colorAccent attribute is used for widget tinting throughout the app and thus should be used for consistency

Stanojkovic
  • 1,612
  • 1
  • 17
  • 24
1

Try using android:backgroundTint="#yourUnderlineColor".

Only available for API 21 and higher.

Rafa0809
  • 1,733
  • 21
  • 24
0

To make it work in Android 6, create your custom theme in res/values-v21/styles.xml .

<style name="FormFont" parent="@android:style/TextAppearance.Medium">
    <item name="colorControlNormal">#c5c5c5</item>
</style>
<style name="FormFontWhite" parent="@android:style/TextAppearance.Medium">
    <item name="colorControlNormal">#ffffff</item>
</style>

and apply then in your EditText

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/FormFont"/>

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/FormFontWhite"/>

For more info check @reVerse answer .

Hope this helps!

Community
  • 1
  • 1
Gueorgui Obregon
  • 5,077
  • 3
  • 33
  • 57
0
<android.support.v7.widget.AppCompatEditText
                    android:id="@+id/password"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/cux_label_password"
                    android:inputType="textPassword"
                    app:theme="@style/editTextStyle" />

  <style name="editTextStyle" parent="TextAppearance.AppCompat">
        <item name="colorControlNormal">#FFFFFF</item>
        <item name="colorControlActivated">#FFFFFF</item>
        <item name="colorControlHighlight">#FFFFFF</item>

    </style>
hepizoj
  • 243
  • 4
  • 9