Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing bottom line colour of edittext

I am trying to change the bottom line colour of EditText but it is showing default blue line colour.I failed to understand where am I going wrong?

<EditText
        android:id="@+id/searchtext"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="15dp"
        android:textColor="#000000"
        android:layout_alignParentTop="true"
        android:maxLines="1"
        android:singleLine="true"
        android:layout_toLeftOf="@+id/usericonlayout"
        android:padding="7dp"
        android:layout_marginTop="10dp"
        android:hint="Search for all GIFs"
        android:textColorHint="#A0A0A0"
        android:shadowColor="@color/border_gray"
        android:theme="@style/EditTextStyle"/>

styles.xml

  <style name="AppBaseTheme" parent="android:Theme.Light">

        <item name="colorAccent">@color/border_gray</item>
        <item name="android:editTextStyle">@style/EditTextStyle</item>
    </style>
   <style name="AppTheme" parent="AppBaseTheme">

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

I also tried -

edittext.getBackground().setColorFilter(getResources().getColor(R.color.border_gray), PorterDuff.Mode.SRC_ATOP);

but didn't worked

like image 763
user3684678 Avatar asked Mar 23 '15 13:03

user3684678


1 Answers

I think you are trying to implement material design in your app. First of all there should be only two values folder in your res folder. 1. values (For version < 21) 2. values-v21

styles.xml for version < 21

<style name="AppBaseTheme" parent="Theme.AppCompat.Light">

        ....
        <item name="android:editTextStyle">@style/EditTextStyle</item>
</style>

<style name="EditTextStyle" parent="Widget.AppCompat.EditText">
         <item name="colorControlNormal">@color/border_gray</item>
         <item name="colorControlActivated">@color/border_gray</item>
         <item name="colorControlHighlight">@color/border_gray</item>
</style>

And for v21

<style name="AppBaseTheme" parent="@android:style/Theme.Material.Light">
    .....
     // Your style here
</style>
like image 143
Pooja Avatar answered Nov 08 '22 01:11

Pooja