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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:29:27+00:00 2026-06-05T19:29:27+00:00

I have some CheckBoxPreferences and I have no problem changing the icon for them

  • 0

I have some CheckBoxPreferences and I have no problem changing the icon for them through xml as shown below and here but since the user has other ways of triggering the checkbox’s actions than directly clicking on it (i.e. perhaps in another activity or even another application) I want to be able to programmatically set the icon depending on value changes that occur along with the action. For example, if Bluetooth is on, I want the icon to be one image and when bluetooth is off, I want it to be a different image. Is it possible to programmatically change this image?

<CheckBox xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+android:id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/check_box_icon"
android:clickable="true"
android:focusable="false"
android:/>
  • 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-05T19:29:28+00:00Added an answer on June 5, 2026 at 7:29 pm

    Found the solution:

    I used the method found in the link that I’d provided in the question to set a selector so that I could use that with all of my CheckBoxPreferences for the different images based on the current state of the checkbox:-

    <?xml version="1.0" encoding="utf-8"?>
    //This is the xml selector "@drawable/checkbox"
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
     <item android:state_checked="false"
      android:drawable="@drawable/checkbox_off_background" />
     <item android:state_checked="true"
      android:drawable="@drawable/checkbox_on_background" />
    </selector> 
    

    Accordingly, the CheckBoxPreference code changes as well:-

    <CheckBox android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:text="new checkbox"
    android:button="@drawable/checkbox"
    android:clickable="true"
    android:focusable="false" />
    

    Now, I can call Checkbox.setChecked() to check whether it’s enabled or not, and also to change it according to the values by setting it to true or false. So, according to the xml properties this will automatically change the icon as well.

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

Sidebar

Related Questions

I have some JavaScript which is changing an image correctly but once it has
I have some problem with the Facebook plugins in the site: www.talnavarro.com In some
I have some sentences that I want to parse. Here is what I have
i have some data saved in a xml file. Those will be displayed in
I have some code in jQuery that iterate through children in div using each().
I have some Haskell code that does work correctly on an infinite list, but
I have some json formatted data that I parse with JSON.parse. The problem I
I have some problem when I try to run maven on netbeans the netbeans-console
I have some problem while configuring symfony project on the production server. When I
I have some tabs on the top of the screen.Below that theres a ListView.

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.