0

how to change the default color orange when tyoping text in edittext field or press button how that color will change? any help?? this is my xml below when i run this code default orange color is appear on border of edittext and when pressing button

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical" 
 android:background="#ffffff">

<TextView
    android:id="@+id/txtEnterPinForTransaction"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="" />
<TextView
    android:id="@+id/lblPinno"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="" />

<EditText
    android:id="@+id/txtPinno"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="textPassword" />

<Button
    android:id="@+id/btnsubmit"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="80dp"
    android:layout_height="wrap_content"
    android:text="Submit" />

<Button
    android:id="@+id/clearButton"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="80dp"
    android:layout_height="wrap_content"
    android:text="Clear" />

<Button
    android:id="@+id/btngoback"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="80dp"
    android:layout_height="wrap_content"
    android:text="Go Back" />

Akram
  • 7,548
  • 8
  • 45
  • 72
Sincere Friend
  • 31
  • 1
  • 1
  • 7

1 Answers1

2

You can create an stateListdrawable which defines, different colors or drawables for different states of Button, and can set this xml drawable as background of the button.

For example for the button you can use following code:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
          android:drawable="@drawable/button_pressed" /> <!-- pressed -->
    <item android:state_focused="true"
          android:drawable="@drawable/button_focused" /> <!-- focused -->
    <item android:state_hovered="true"
          android:drawable="@drawable/button_focused" /> <!-- hovered -->
    <item android:drawable="@drawable/button_normal" /> <!-- default -->
</selector>

save this xml into Res-> drawable folder with btn_selector.xml, now set this to background of the button:

<Button
    android:id="@+id/btnsubmit"
    android:background="@+drawable/btn_selector"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="80dp"
    android:layout_height="wrap_content"
    android:text="Submit" />

If still something unclear, refer

http://developer.android.com/guide/topics/resources/drawable-resource.html

jeet
  • 29,001
  • 6
  • 52
  • 53