1. Download our Official Android App: Forums for Android!

Apps Checkbox custom style

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

  1. bravotango

    bravotango Lurker
    Thread Starter
    Rank:
    None
    Points:
    25
    Posts:
    4
    Joined:
    Sep 3, 2011

    Sep 3, 2011
    4
    0
    25
    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
     

    Advertisement

  2. alostpacket

    alostpacket Over Macho Grande?
    Rank:
    None
    Points:
    513
    Posts:
    7,972
    Joined:
    Nov 29, 2009

    Nov 29, 2009
    7,972
    3,603
    513
    Android App Developer
    NY
    moved to our app dev section :)
     
  3. jonbonazza

    jonbonazza Android Expert
    Rank:
    None
    Points:
    163
    Posts:
    1,930
    Joined:
    Jul 13, 2010

    Jul 13, 2010
    1,930
    457
    163
    Male
    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
    Rank:
    None
    Points:
    25
    Posts:
    4
    Joined:
    Sep 3, 2011

    Sep 3, 2011
    4
    0
    25
    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?
    Rank:
    None
    Points:
    513
    Posts:
    7,972
    Joined:
    Nov 29, 2009

    Nov 29, 2009
    7,972
    3,603
    513
    Android App Developer
    NY
    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
    Rank:
    None
    Points:
    25
    Posts:
    4
    Joined:
    Sep 3, 2011

    Sep 3, 2011
    4
    0
    25
    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.
     

Share This Page

Loading...