0

I'm developing Android app for 4.0 version, and all checkboxes have got a black background for tick, but I need white. If I use "background" xml attribute as "white" then all checkbox (with text) is white; I need only white place for tick.

user2218845
  • 1,081
  • 4
  • 16
  • 21

3 Answers3

0

The most simple way - emulate CheckBox using ImageView with 3 background states (stateSelected=true, stateSelected=false, statePressed = true).
Just create appropriate xml file with 3 backgrounds and set it to ImageView background.
Then in code, when click on ImageView just switch ImageView.setSelected = !ImageView.isSelected.

Hope its help

jimpanzer
  • 3,470
  • 4
  • 44
  • 84
0

I dont know if i am extremely late or what, but here is the solution

Code snippet:

say this selector is name "checkbox_selector"

<?xml version="1.0" encoding="utf-8"?>
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:state_checked="true" 
    android:drawable="@drawable/cbchk_blue"
    android:state_focused="false">
</item>
<item android:state_checked="true" 
    android:drawable="@drawable/cbchk_blue"
    android:state_focused="true">
</item>
<item android:state_checked="false" 
    android:drawable="@drawable/cbunchk_blue"
    android:state_focused="false">
</item>
<item android:state_checked="false" 
    android:drawable="@drawable/cbunchk_blue"
    android:state_focused="true">
</item>

in order to set it just for the checkbox and not the entire text also, you could have it as:

<CheckBox
     android:layout_width="45dip"
     android:layout_height="wrap_content"
     android:layout_centerVertical="true"
     android:button="@drawable/checkbox_selector"
     android:text="@string/text_here" />
Community
  • 1
  • 1
0

Maybe my solution is not very elegant, but it works for me:

I simplily create another layout with the dimensions of the checkbox rectangle (15x15) and with white background. Then I add this layout to a RelativeLayout, where I also put the checkbox. With a margin of 9dp, I put the white layout-rectangle below the checkbox, so it seems that the checkbox bacground color is white.

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/login_large_margin"
            android:layout_marginTop="@dimen/login_medium_margin" >

            <RelativeLayout
                android:layout_width="15dp"
                android:layout_height="15dp"
                android:layout_margin="9dp"
                android:background="@color/white" >
            </RelativeLayout>

            <CheckBox
                android:id="@+id/login_check"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:fontFamily="sans-serif-light"
                android:text="@string/login_check"
                android:textColor="@color/white" >
            </CheckBox>
        </RelativeLayout>
bpz
  • 350
  • 1
  • 3
  • 9