user2276872
user2276872

Reputation:

Change Border Color of Edittext

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

Upvotes: 0

Views: 4169

Answers (2)

Ragul S V
Ragul S V

Reputation: 139

Use the below step to change the border color.

  • editText.Background.SetColorFilter(Color.Red);

Upvotes: 0

Rod_Algonquin
Rod_Algonquin

Reputation: 26198

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.

Upvotes: 1

Related Questions