1

How can I change underline color for TextView in Android? Desired result shown below: Underline color

Default is some kind of blue (probably holo blue), but I need to change this to orange. The problem is, I don't know how exactly is this called (is this underline, indicator or what?), so I'm not able to google this on my own.

Thanks

vanomart
  • 1,739
  • 1
  • 18
  • 39

2 Answers2

0

You have two options, for a basic edit text you could use either of these. The second option is not covered in the question flagged by karaokyo and would be my preference to reduce application size.

You can use the Android Holo Colors web app to generate custom themes, you choose the color and which controls you want and it generates the 9 patches and appropriate theme files. May require a little tinkering to get it to fit into your current project but all you need is in the generated zip.

Alternatively with Android 5 you have Widget Tinting, which is also supported in older Android versions by using AppCompat v21. This does all the coloring for you without all the extra resources to include. Note that this doesn't work everywhere yet but if you are using a plain edit text on an activity it should be ok. Full details of implementation here

CodeChimp
  • 4,745
  • 6
  • 45
  • 61
0

This is how I managed it:

The idea is to change the background of the textbox, wich is the one that includes the color for the underline, the background is the one that draws the line. The color is controlled by the "Tint" however if you just change the Tint from the the control directly you would change the tint for all the controls that use that background instance, i.e. all the TextViews Widgets in your app. If you only need to change the color on a single control, you need to clone the background drawable and modify it's tint. Mutate is the method that actually creates the new instance.

My example is part of a xamarin custom renderer, however it could just as simply apply to java, if you switch the method names to lowercase i think.

    var background = YourTextView.Background.GetConstantState().NewDrawable();
    background.Mutate();
    background.SetTint(newLineColor.ToAndroid());
    YourTextView.SetBackground(background);
alexcons
  • 651
  • 6
  • 5