Change the color of the bottom line of an edittext

I am trying to change the color of the bottom of an EditText, but it shows the default blue line color. I do not understand where I am 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 did not work

+5
source share
3 answers

I think you are trying to implement material design in your application. First of all, in the res folder there should only be a folder with two values. 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> 
+5
source

If you are using Api lvl> = 21, you need to put the namespace "android:" in front of each attribute you specify.

If you are using AppCompat, you need to change the parent theme of Theme:

 @style/Theme.AppCompat.Light 
0
source

there he is..

 <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableBottom="@color/yourColor"/> 
-1
source

Source: https://habr.com/ru/post/1215912/


All Articles