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

  • Home
  • SEARCH
  • 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 9198433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:16:53+00:00 2026-06-17T22:16:53+00:00

We know that in android application we can change background color of checkboxes by

  • 0

We know that in android application we can change background color of checkboxes by using SetButtonDrawable and a xml file.

This xml file can be define with gradients or a simple file that used images in drawables.
This article show a sample with Gradients: Android: Set color of CheckBox

And also this is another sample that i used:

 <item android:state_checked="true">
    <layer-list>
        <item>
            <shape android:shape="rectangle">
                <solid android:color="#9b9b9b" />
                <corners android:radius="5dp" />

            </shape>
        </item>
        <item android:top="2dp" android:left="1.5dp" >
            <shape  android:shape="rectangle">
                <solid android:color="#ffffff" />
                <corners android:radius="5dp" />
                <size android:height="20dp" android:width="20dp" />
            </shape>
        </item>
        <item android:top="2dp" android:bottom="1dp" android:left="1.5dp">
            <shape  android:shape="rectangle">
                <gradient android:startColor="#ff7dbce9" android:endColor="#ff2578b3" android:angle="270" />
                <corners android:radius="5dp" />
                <size android:height="20dp" android:width="20dp" />
            </shape>
        </item>
        <item android:top="2dp" android:bottom="1dp" android:left="1.5dp">
            <shape  android:shape="rectangle">
                <gradient android:startColor="#ff7dbce9" android:endColor="#ff2578b3" android:angle="270" />
                <corners android:radius="5dp" />
                <size android:height="20dp" android:width="20dp" />
            </shape>
        </item>
        <item>
            <bitmap android:gravity="center" android:src="@drawable/tick_red_icon"/>
        </item>
    </layer-list>
</item>
<item >
    <layer-list>
        <item>
            <shape android:shape="rectangle">
                <solid android:color="#9b9b9b" />
                <corners android:radius="5dp" />
            </shape>
        </item>
        <item android:top="2dp" android:left="1.5dp" >
            <shape  android:shape="rectangle">
                <solid android:color="#ffffff" />
                <corners android:radius="5dp" />
                <size android:height="20dp" android:width="20dp" />
            </shape>
        </item>
        <item android:top="2dp" android:bottom="2dp" android:left="1.5dp">
            <shape  android:shape="rectangle">
                <solid android:color="#e5e4e4" />
                <corners android:radius="5dp" />
                <size android:height="20dp" android:width="20dp" />
            </shape>
        </item>
    </layer-list>
</item>

Also we know that if we wanna change the gradient colors we need to define it as a DrawableGradient in runtime and then use this.

The question is this: How can we define some comlex gradients like above as DrawableGradient to have the ability that change them color on runtime?

Or if there is a bad solution is there any better solution that we set the background color of checkboxes and can changes their color on runtime?

  • 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-17T22:16:55+00:00Added an answer on June 17, 2026 at 10:16 pm

    Finally by research I found this article and based on this I developed a code that is this question’s answer.

    We have to define each layer in a separate xml file like this:

     <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
            <item>
                <shape android:shape="rectangle">
                    <solid android:color="#9b9b9b" />
                    <corners android:radius="5dp" />
    
                </shape>
            </item>
            <item android:top="2dp" android:left="1.5dp" >
                <shape  android:shape="rectangle">
                    <solid android:color="#ffffff" />
                    <corners android:radius="5dp" />
                    <size android:height="20dp" android:width="20dp" />
                </shape>
            </item>
            <item android:top="2dp" android:bottom="1dp" android:left="1.5dp" android:id="@+id/mainImage">
                <shape  android:shape="rectangle">
                    <gradient android:startColor="#ff7dbce9" android:endColor="#ff2578b3" android:angle="270" />
                    <corners android:radius="5dp" />
                    <size android:height="20dp" android:width="20dp" />
                </shape>
            </item>
            <item android:top="2dp" android:bottom="1dp" android:left="1.5dp" android:id="@+id/TheinImage">
                <shape  android:shape="rectangle">
                    <gradient android:startColor="#ff7dbce9" android:endColor="#ff2578b3" android:angle="270" />
                    <corners android:radius="5dp" />
                    <size android:height="20dp" android:width="20dp" />
                </shape>
            </item>
            <item>
                <bitmap android:gravity="center" android:src="@drawable/ic_menu_ca_dis"/>
            </item>
        </layer-list>
    

    and then by retrieving them on run-time we can change their items.(Layer is the name of my xml file)

    GradientDrawable gd = new GradientDrawable
                (GradientDrawable .Orientation .TopBottom,
                 new int[]{Color.Red , Color.Green });
            gd.SetStroke (10, Color.Blue );
    LayerDrawable ld = (LayerDrawable) Resources .GetDrawable  (Resource .Drawable.Layer   );
            bool testfactor = ld.SetDrawableByLayerId (Resource .Id.mainImage , gd);
    

    Now, by using StateListDrawable we can define witch state is related to witch layer:

        StateListDrawable states = new StateListDrawable();
            states.AddState (new int[] {Android .Resource .Attribute .StateChecked },
            ld);
            states.AddState(new int[] { },
            Resources .GetDrawable (Resource .Drawable .ic_menu_ca_dis   ) );
    

    Now, you can join changing this xml in runtime 🙂

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

Sidebar

Related Questions

How to make android icons with transparent background using eclipse.I know that we can
I know that eclipse can do this, can Intellij via the new Android support
I know that a style can be inherited in android via the parent property
I wanted to know that how can we find how much time android device
I want to know that how to follow a page on Twitter using android
I know that Android doesn't have an Application-level onPause the way an Activity has
I recently discovered that you can describe an Android custom drawable in an XML
I'm working on an Android application that will send MMS internally without using the
Background I'm writing a graphing library for an android application (yes yes, I know
I know that for opening android application from a link inside a web page

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.