EyeQ Tech
EyeQ Tech

Reputation: 7358

Creating style for checkbox

I'm putting some settings to the checkbox, and it works. But when I take them into a style and apply them, it doesn't. Per below, first button uses the style (NOT working), second one direct settings (works). What's wrong with my style file, per below? Tks

    <CheckBox android:id="@+id/mon"
        android:text ="Mon"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:contentDescription="Monday"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        style="@style/FilledCheckButton"

    />
    <CheckBox android:id="@+id/tue"
        android:text="Tue"
        android:layout_width="80dp"
        android:layout_height="80dp"

        android:contentDescription="Tuesday"

        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/mon"
        android:gravity="center"
        android:background="@drawable/v4_btn_weekday"
        android:button="@drawable/v4_btn_weekday"
     />

My style file:

<?xml version="1.0" encoding="utf-8"?>
<resources  xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="FilledCheckButton" parent="android:style/Widget.CompoundButton.CheckBox"
        android:background="@drawable/v4_btn_weekday"
        android:button="@drawable/v4_btn_weekday"
        android:gravity="center">
    </style>

</resources>

enter image description here

Upvotes: 0

Views: 48

Answers (1)

M D
M D

Reputation: 47807

Try this way

<?xml version="1.0" encoding="utf-8"?>
<resources  xmlns:android="http://schemas.android.com/apk/res/android">

<style name="FilledCheckButton" parent="@android:style/Widget.CompoundButton.CheckBox">
   <item name="android:background">@drawable/v4_btn_weekday</item>
   <item name="android:button">@drawable/v4_btn_weekday</item>
   <item name="android:gravity">center</item>
</style>

For more information go to http://aproblemlikemaria.wordpress.com/2011/09/26/theming-and-styling-in-android/

Upvotes: 1

Related Questions