Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AppCompat and EditText different underline on different API

I'm trying to make underline line color change for EditText (it will be used for input's validation, so it must be able to change in runtime).

I'm using AppCompat library. The problem is that on API 21 and above, I see transparent black line (gray overlay), instead of bolded version.

How to make it the same as in API 16?

I used this code to change tint:

    final Drawable originalDrawable = view.getBackground();
    final Drawable wrappedDrawable = DrawableCompat.wrap(originalDrawable);
    DrawableCompat.setTint(wrappedDrawable, Color.RED);
    setBackground(view,wrappedDrawable);

Pic

like image 687
Damian Kozlak Avatar asked Jun 29 '15 14:06

Damian Kozlak


2 Answers

Solution found by adding these lines to my theme:

    <item name="editTextStyle">@style/Base.V7.Widget.AppCompat.EditText</item>
    <item name="editTextBackground">@drawable/abc_edit_text_material</item>
like image 183
Damian Kozlak Avatar answered Sep 28 '22 08:09

Damian Kozlak


You should not change the background. It's better if you create a theme, and use theme colors (colorPrimary, colorAccent are the most important for widgets) to get the desired effect. Assign the theme to your EditText and enjoy. Note: you should use one of the AppCompat theme as base theme.

<style name="AppTheme.Base" parent="Theme.AppCompat.NoActionBar">
    <item name="colorPrimary">@color/primary</item>
    <item name="colorAccent">@color/accent</item>
</style>

and in your colors.xml

<color name="primary">#ff0000</color>
<color name="accent">#00ff00</color>
like image 40
Mimmo Grottoli Avatar answered Sep 28 '22 08:09

Mimmo Grottoli