Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change text background color of a button in Android?

I have searched a lot but I haven't found what I want. What I’m planning to do is to change the background colour of text on a button. I’m not interested in changing the colour on click. I just want to change the background of the text on a button. Thank you.

Edit: This is a sample. I want to change the black colour if it possible.

http://i.imgur.com/B8tYnEN.png

like image 723
Mansour Fahad Avatar asked Sep 25 '13 07:09

Mansour Fahad


2 Answers

Use this to set the text color of Button :

setTextColor(getResources().getColor(R.color.white));

or

android:textColor="@color/white"

Use this to set the background of the button :

setBackgroundResource(R.drawable.button_img);

or

android:background="@drawable/button_img"

or

android:background="@color/blue"
like image 64
Permita Avatar answered Sep 20 '22 21:09

Permita


Maybe you should try to use RelativeLayout instead of Button. Something like this: `

<RelativeLayout
    android:id="@+id/RelativeLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:clickable="true"
    android:background="#ffffff" >
  <TextView
        android:id="@+id/TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Text"
        android:textColor="#ffffff"
        android:background="#000000"
        android:textSize="16sp" />
</RelativeLayout>`
like image 43
subasa Avatar answered Sep 21 '22 21:09

subasa