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 7051059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:13:07+00:00 2026-05-28T03:13:07+00:00

I want to customize Buttons for my application. The application has a color picker

  • 0

I want to customize Buttons for my application. The application has a color picker where the user will select color and I have to set that particular start/end color to the buttons. These colro values will be stored in an object “Utility”.

Basically from start only, I want to use “Utility” object to set colors for background, text color, font, etc. And again when the color is changed by the user I got to change it to the buttons and refresh them. And also to save colors in a file, so next time user starts app, it comes up with the last color selected.

I couldn’t find <selector> to be the best option, as I wont be able to change the color in xml. What can be the best option for such requirement ?

UPDATIONS :
@jitendra, from your answer I got somethign helpful. I use GradientDrawable to set colors of my buttons. In my onCreate() of the Activity, I call a method RefreshComponents() that sets the background of root, text color/size of buttons and gradient colors of the buttons. It works properly, but the only problem I see is the on applying GradientDrawable to the button the gap between 2 buttons is lost.

This is the image WITHOUT applying GradientDrawable :
enter image description here

On applying GradientDrawable the output is :
enter image description here

You see the size of button is increased a bit from all the sides. If I apply to next button also, they both touch eachother. My xml for the above is :

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/mainroot" android:layout_width="fill_parent"    
  android:layout_height="fill_parent" android:orientation="vertical"
  android:paddingTop="35dip" android:paddingBottom="35dip" 
  android:paddingLeft="35dip" android:paddingRight="35dip"android:gravity="center" >

   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/mainrow1" android:layout_width="fill_parent"
      android:layout_height="wrap_content" android:orientation="horizontal" 
      android:layout_marginBottom="15dip" android:gravity="center_horizontal" >
         <Button android:text="Accounting" android:id="@+id/accBtn" android:layout_width="80dip" style="@style/TileButtonStyle"  />
        <Button android:text="Data" android:id="@+id/dataBtn" android:layout_width="80dip" android:layout_height="fill_parent"></Button>
        <Button android:text="Information" android:id="@+id/infoBtn" android:layout_width="80dip" android:layout_height="fill_parent" android:ellipsize="end"></Button>
  </LinearLayout>
  ..... Other lineasr layout with same parameters as above child 

And the GradientDrawable that I create is :

    public static GradientDrawable getButtonDrawable(Button btn) {
    int colors[] = {getStartColor(), getEndColor()};
    GradientDrawable grad = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, colors);
    grad.setCornerRadius(5f);
    return grad;
}

And finally in my onCreate(), I add :

    GradientDrawable btnGradient = Utility.getButtonDrawable(btn1); 
btn1.setBackgroundDrawable(btnGradient);

What is going wrong here ? Is the margin around the button becoming 0 ? Do I have to set bounds for the grad, or again set LayoutParams for the button ?

Any help is appreciative to help me achieve my goal.

Thanks

  • 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-05-28T03:13:08+00:00Added an answer on May 28, 2026 at 3:13 am

    Oh I got the solution :

    I added layout_marginRight attribute to buttons and that did the work.

    Though I am still concerned, without GradientDrawable the buttons had margin betweenthem then after applying GradientDrawable why is the default margin lost ? Why is the need of additional layout_marginRight to be added ?

    If anyone yet has answer for this, please let me know.

    Thanks

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

Sidebar

Related Questions

I have used Facebook invite friend application,I want to customize the Facebook buttons and
I want to customize a video player to have additional buttons and controls using
I want to customize a .NET build process so that I can run an
I want to customize the parameter in createuser() method Membership Provider, Actually, i have
I have mp3 catalog portal and I want to customize my urls. I used
I want allow the user to customize their web pages on my ASP.NET MVC
I want to customize actionbar buttons with an image both for pressed and not
SALAM I want to customize the html text, buttons and text fields with CSS
I want to customize the images on increment and decrement buttons in spark numericstepper
I want to customize my CheckBox on my Android mechine, but it has different

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.