1. Are you ready for the Galaxy S20? Here is everything we know so far!

Checkbox custom style

Discussion in 'Android Development' started by bravotango, Sep 3, 2011.

  1. bravotango

    bravotango Lurker
    Thread Starter

    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
     



    1. Download the Forums for Android™ app!


      Download

       
  2. alostpacket

    alostpacket Over Macho Grande?

    moved to our app dev section :)
     
  3. jonbonazza

    jonbonazza Android Expert

    put your checkboxthem.xml in the drawable folder and in your layout file, for the checkbox, set thebackground attribute to "@drawable/checkboxtheme"
     
    bravotango likes this.
  4. bravotango

    bravotango Lurker
    Thread Starter

    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.
     
  5. alostpacket

    alostpacket Over Macho Grande?

    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.
     
    bravotango likes this.
  6. bravotango

    bravotango Lurker
    Thread Starter

    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.
     
Loading...
Similar Threads - Checkbox custom style
  1. Hadron
    Replies:
    6
    Views:
    389
  2. Yesi Trotamundos
    Replies:
    6
    Views:
    522
  3. Hakeem balogun
    Replies:
    0
    Views:
    327
  4. kumaranil13k
    Replies:
    7
    Views:
    570
  5. kumaranil13k
    Replies:
    11
    Views:
    572
  6. Ben Foster
    Replies:
    1
    Views:
    342
  7. Sky Weatherman
    Replies:
    2
    Views:
    438
  8. RianRusdani
    Replies:
    3
    Views:
    514
  9. 14km
    Replies:
    2
    Views:
    384
  10. little_star
    Replies:
    1
    Views:
    790

Share This Page

Loading...