Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8296583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:04:57+00:00 2026-06-08T15:04:57+00:00

When i say button.setBackgroundColor(Color.BLUE); the button shape changes to rectangle from default shape. I

  • 0

When i say

 button.setBackgroundColor(Color.BLUE);

the button shape changes to rectangle from default shape. I want to change the button color without affecting its original shape. Please help me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T15:04:58+00:00Added an answer on June 8, 2026 at 3:04 pm

    Whenever you change the default background of your button the shape is going to change as the default shape is rectangle and the default background is a shape drawable with rounded corners. If you use any other background this rounded corner effect is lost.

    You can achieve the same effect with any color or shape if you use a shape drawable as the background.
    Here is how you can achieve this:

    1. Create a shape drawable.
    2. Use this drawable as the button’s background.

    sample code for shape drawable:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" >
        <solid
            android:color="#f8f8f8"/>
        <corners
            android:radius="4dp"/>
        <padding 
            android:left="10dp"
            android:right="10dp"
            android:top="5dp"
            android:bottom="5dp"/>
        <stroke 
            android:width="1dp"
            android:color="#aeaeae"/>
    </shape>
    

    If you want to have a button with a selector then use this xml as the background

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android" >
        <item android:state_pressed="true">
            <shape >
                <solid
                    android:color="#ff0000" />
                <stroke 
                    android:width="1dp"
                    android:color="#ff0000" />
                <corners
                    android:radius="4dp" />
                <padding
                    android:left="10dp"
                    android:right="10dp"
                    android:top="10dp"
                    android:bottom="10dp" />
            </shape>
        </item>
        <item >
            <shape >
                <gradient
                    android:startColor="#ff2727"
                    android:endColor="#890000"
                    android:angle="270" />
                <stroke
                    android:width="1dp"
                    android:color="#620000" />
                <corners
                    android:radius="4dp" />
                <padding
                    android:left="10dp"
                    android:right="10dp"
                    android:top="10dp"
                    android:bottom="10dp" />
            </shape>        
        </item>
    </selector>
    

    This is a selector xml with items as the different shape drawables. If the button is pressed that is the button’s state is state_pressed then the top shape drawable is used else the bottom shape drawable is used.

    I hope this will help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to provide a button which cancels the present task, Let's say I
From the Designer in VS let's say you double click on a button and
I have a control on a page (let's say a button). I want to
How do I change the Content property of say a Button? Maybe with StringAnimationUsingKeyFrames?
I have noticed when user clicks on a link with, say middle button, or
I have 3 edittexts with input type as number and 1 button that say
Lets say for example: $(.button).click(function() { $.post(commandrunner.php, { param1: 'value', param2: 'value2', param3: 'value3'
Lets say we have a textbox and an button. And the user write table
Lets say i had a a button that cycles through numbers how can i
Let's say I have a button.. how can I distinguish between single click and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.