将星形样式应用于Android中的复选框

时间:2012-07-13 07:58:01

标签: android checkbox android-widget styles android-xml

style="?android:attr/starStyle" 

将此代码应用于复选框属性后,我无法查看该复选框。代码中是否有错误?

2 个答案:

答案 0 :(得分:10)

发布完整的xml文件。它对我有用:

<CheckBox
    android:id="@+id/checkBox1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    style="?android:attr/starStyle"
    android:text="CheckBox" 
/>

答案 1 :(得分:4)

检查下面的代码,它可以帮助你...

在您的布局文件中

复选框...

<CheckBox
        android:id="@+id/Check"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="5dp"
        android:text="  Not connected "
        android:textSize="14sp"
        android:textStyle="bold"
        android:textColor="#ccc"
        android:clickable="true"
        android:focusable="true" 
        android:button="@drawable/check"/>

在R / drawable / check.xml中 - 使用此处的星图而不是我的图像。

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

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item 
        android:state_checked="true" 
        android:state_window_focused="true"
        android:state_enabled="true"
        android:drawable="@drawable/check_on" />

    <item 
        android:state_checked="false" 
        android:state_window_focused="true"
        android:state_enabled="true"
        android:drawable="@drawable/check_off" />
</selector>
相关问题