0

I tried making a 9 patch image and setting that as background as many solutions suggest but that didn't change the border color when the edittext is selected. In fact, there is no border now, just the image of the edittext. How can I simply change the border color of it? To be for example blue instead of yellow. enter image description here

  • Refer to this http://wptrafficanalyzer.in/blog/changing-background-color-and-border-color-of-an-edittext-widget-using-state-list-in-android/ – Aniruddha Jun 17 '14 at 06:06

2 Answers2

1

You need to make a selector when the Edittext is focused or selected the image changes of the Edittext.

sample:

<?xml version="1.0" encoding="utf-8"?>
<selector 
    xmlns:android="http://schemas.android.com/apk/res/android"
    >
    <item 
        android:state_pressed="true"
        android:drawable="@android:drawable/edittext_pressed"/> //9patch for pressed 
    <item 
        android:state_focused="true"
        android:drawable="@drawable/edittext_focused"/> //9patch for focused
    <item 
        android:drawable="@android:drawable/edittext_normal"/> //9patch for normal
</selector>

This selector is then added in the background of the Edittext.

Rod_Algonquin
  • 26,074
  • 6
  • 52
  • 63
  • Tried it and says Rendering Problems NOTE: One or more layouts are missing the layout_width or layout_height attributes. These are required in most layouts. does not set the required layout_width attribute:..... what is this? =/ –  Jun 17 '14 at 05:40
  • @darkchampionz put it in the drawable folder not in the layout folder – Rod_Algonquin Jun 17 '14 at 05:41
  • I go in res -> drawable-xhdpi and create the xml there. but then it is placed under layout folder automatically D: –  Jun 17 '14 at 05:42
  • @darkchampionz just try to put it in the drawable just drawable np dpi extension – Rod_Algonquin Jun 17 '14 at 05:43
  • Copy and pasted from http://stackoverflow.com/questions/11485595/change-edittext-border-color?? – Aniruddha Jun 17 '14 at 05:45
  • thanks for your help. looks like this point is only missing. however I have no drawable folder. source -> main -> res then there are only drawables dpi folders =/ –  Jun 17 '14 at 05:46
  • @darkchampionz make sure that you create xml first; right click drawable-xhdpi --> new --> android xml --> Resource type drawable – Rod_Algonquin Jun 17 '14 at 05:48
  • under xml, it gives me only the options of layout xml file and values xml file –  Jun 17 '14 at 05:52
  • @darkchampionz that is weird... try to create a new folder named drawable in the res folder. – Rod_Algonquin Jun 17 '14 at 06:02
  • @darkchampionz create one xml file, it's ok if it is of type layout. After creating, open it and replace everything with the above code. Make sure that xml file is under drawable. – Aniruddha Jun 17 '14 at 06:04
  • ok took some time to figure it out, had to go new -> file -> drawable resource file (f*k androidstudio). thanks for your help and patience. I will continue to check if rest works too –  Jun 17 '14 at 06:16
0

Use the below step to change the border color.

  • editText.Background.SetColorFilter(Color.Red);
Ragul S V
  • 139
  • 6