• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Checkbox custom style

Hello Android experts. As a new starter in android I am finding it almost impossible to create a custom style checkbox. Maybe this is not possible.
I am using Eclipse for Java Developers Indigo Release with Android open source plugin.
I see lots of examples showing a pretty silver checkbox but what I am getting is a smaller dark gray checkbox no matter what version of android I choose for the project. I have searched a lot and have not found anyone else experiencing this problem.
If I try to customise the checkbox to make it look like the examples the black border outline of the unwanted built-in checkbox persists and is superimposed on my custom image style.
I have to use android:background="@layout/checkboxtheme" to get this to work at all. Using style="@layout/checkboxtheme" has no effect.
I would show an image to make this clearer but am not at liberty to do this yet as I have not made enough posts.
Here is my main.xml:

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

<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android=""
androidrientation="vertical">

<CheckBox android:id="@+id/check1"
android:background="@layout/checkboxtheme"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>

<CheckBox android:id="@+id/check2"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>

<Button android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Confirm Selection"/>

<TextView android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Selected is" />

<EditText android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="EditText"
android:textSize="18sp"/>
</LinearLayout>

Here is my checkboxtheme.xml

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

<selector xmlns:android="">
<item android:state_checked="true" android:state_focused="true"
android:drawable="@drawable/btn_check_off_pressed" />
<item android:state_checked="false" android:state_focused="true"
android:drawable="@drawable/btn_check_off_selected" />
<item android:state_checked="false"
android:drawable="@drawable/btn_check_off" />
<item android:state_checked="true"
android:drawable="@drawable/btn_check_on" />
</select
 
put your checkboxthem.xml in the drawable folder and in your layout file, for the checkbox, set thebackground attribute to "@drawable/checkboxtheme"
 
Still same problem no matter whether the theme is in layout or drawable makes no difference.

After a bit more research found I was trying to create the project using Android 2.3 using images from version 2.2 so the dark gray checkbox is the default for version 2.3.

I now believe it is not possible to mess with custom checkbox images.
 
I think you'll find the entire theme systems is a bit clunky. It will work on some phones and not others. Some manufacturers will skin one way, others another way. It can be a bit of a headache. Mostly I stick to styling things within my app only. And leave menus and preferences screen as they are.
 
Suddenly today it is working without the ugly results albiet on API 8 emulator.
I did relocate the checkboxtheme to drawable folder so I don't know if this had any effect. Some things are possible.
 
Back
Top Bottom