1

I am making an app in android.

There are 3 edittext in one page. I just want to change border color of edit text while in am writing on them . In simple words. Change border color on four.

Right now using this code for background and border color

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#ffffff" />
    <stroke android:width="1dip" android:color="#FF0000" />
</shape>

But want to change onFocus

Szymon
  • 42,577
  • 16
  • 96
  • 114
Android
  • 65
  • 3
  • 7

2 Answers2

2

In your main_activity.xml, in the outermost wrapper say its a linear layout, write these 2 lines:

android:focusableInTouchMode="true"
android:descendantFocusability="beforeDescendants"

and then in the already existing file write ->

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_focused="true"

    >
    <shape >
        <solid android:color="#ffffff" />
<stroke android:width="1dip" android:color="#FF0000" />

    </shape>


</item>

<item android:state_window_focused="false">
    //the code for the edittext which will be by default

</item>

</selector>
Neha Gupta
  • 847
  • 1
  • 8
  • 15
  • Can you mention where to add these two lines given in your comment ? android:focusableInTouchMode="true" android:descendantFocusability="beforeDescendants" – Android Sep 26 '13 at 22:03
  • Yes in your activity_main.xml in the layout folder. Remember to put it in the outermost wrapper. – Neha Gupta Sep 27 '13 at 05:12
0

Make another shape in xml with the color you want to change while typing on it. And with a selector you can change it onfocus.

try it . i think its helpfull.

Android: Using selector to set background color for image view

this link will help you on using seletors.

Community
  • 1
  • 1
Freny John
  • 36
  • 2