Reputation: 228
I'm using Eclipse ADT and I need to know how to change the default color of a form widgets button from the default gray to other color, of course using the xml.
Upvotes: 1
Views: 1049
Reputation: 185
Here is answer my friend
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/grey"/>
Upvotes: 0
Reputation: 3663
Or you can use 9 patch images.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/patch_pressed" android:state_pressed="true"/>
<item android:drawable="@drawable/patch_normal" android:state_enabled="true"/>
<item android:drawable="@drawable/patchdisable" android:state_enabled="false"/>
And in Xml
<Button
android:id="@+id/button_register"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/patch"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="REGISTER"
android:textColor="#ffffff"
android:textStyle="bold" />
Upvotes: 2
Reputation: 13483
Button btn = (Button)findViewById(R.id.button);
btn.setBackgroundColor(Color.BLUE);
btn.setBackgroundColor(Color.rgb(0, 0, 255));
btn.setBackgroundColor(Color.parseColor("blue"));
Add this property to your Button
in your XML file:
android:background="#800080"
#800080
is purple.
Upvotes: 0
Reputation: 1039
In your xml, you can set the background color by using android:background="#FF0000"
<Button
android:id="@+id/loadimage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Load Image"
android:background="#FFFF00"/>
you can set any background color of your choice...:)
Upvotes: 0