Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android button background color

I am trying to set the background color of a button in my app and I am unable to achieve the result that I want...

The color that I am trying to set is holo_green_light(#ff99cc00). In order to do it, I am using setColorFilter(0xff99cc00, PorterDuff.Mode.MULTIPLY);

The color that I get is not the holo_green_light but a mix of lightgrey and holo_green_light.

I have tried using the LightingColorFilter without much success.

Is there a way to do it programatically, so that the button appears like a button and not a flat rectangle with the color that I need.

like image 377
user2260040 Avatar asked Aug 06 '13 00:08

user2260040


People also ask

How can change background color of button in Android?

To set Android Button background color, we can assign android:backgroundTint XML attribute for Button in layout file with the required Color Value. To programmatically set or change Android Button background color, we may call pass the method Button.

How can I change background color of a button?

To change the background color of the button, use the CSS background-color property and give it a value of a color of your taste. In the . button selector, you use background-color:#0a0a23; to change the background color of the button.

What is the default button color in Android?

When I open a new android studio project, the default color for button is purple.

How can I make my Android button more attractive?

Using colors (background, text, border) Using custom shapes like circle, rounded corners and more. You can add images to your buttons to customize them. Using drawables to make gradients, dotted borders and more.


2 Answers

If you want to keep the general styling (rounded corners etc.) and just change the background color then I use the backgroundTint property

android:backgroundTint="@android:color/holo_green_light" 
like image 105
Mark Proctor Avatar answered Sep 17 '22 12:09

Mark Proctor


This is my way to do custom Button with a different color:

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android">     <stroke android:width="3dp"         android:color="#80FFFFFF" />       <corners android:radius="25dp" />       <gradient android:angle="270"             android:centerColor="#90150517"             android:endColor="#90150517"             android:startColor="#90150517" /> </shape> 

This way you set as background:

<Button android:id="@+id/button"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="Button"         android:layout_marginBottom="25dp"         android:layout_centerInParent="true"         android:background="@drawable/button" /> 
like image 33
Bebin T.N Avatar answered Sep 19 '22 12:09

Bebin T.N