0

I changed the Bitmaps of an Android 2.3.4 Checkbox and would like to set the size of the bitmaps to scale them. I changed the checkbox like this:

<CheckBox
    android:id="@+id/cb1"
    android:button="@drawable/checkbox"
    android:layout_alignParentLeft="true"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Sort: 1" />

with the matching xml drawable

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true"  android:state_focused="true"    android:drawable="@drawable/checkbox_on_background_focus_yellow"/>
    <item android:state_checked="false" android:state_focused="true"    android:drawable="@drawable/checkbox_off_background_focus_yellow"/>
    <item android:state_checked="false" android:drawable="@drawable/checkbox_off_background" />
    <item android:state_checked="true"  android:drawable="@drawable/checkbox_on_background" />
</selector>

How can I set a dip/dp value to change the size of the bitmaps of the checkbox ?

HardCoder
  • 3,026
  • 6
  • 32
  • 52

3 Answers3

14

Actually what you could've done to set an image to the size of the checkbox is to put

android:button="@null"
android:background="@drawable/checkbox" <!-- your custom selector -->

With this, your custom checkbox image (in both states, checked and unchecked) will always fit to the size of your checkbox.

Tomap
  • 638
  • 1
  • 8
  • 21
2

I solved it by making the bitmaps the right size. I cannot scale it now but I tested it on several devices with varying dpi settings and it seems fine. For now.

HardCoder
  • 3,026
  • 6
  • 32
  • 52
0

Just define related Drawables and set them into your checkbox properties.

android:background="@drawable/my_background"
Shehzad
  • 2,870
  • 17
  • 21