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

4 checkbox android styles android-widget android-xml

style="?android:attr/starStyle" 
Run Code Online (Sandbox Code Playgroud)

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

Tam*_*seh 10

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

<CheckBox
    android:id="@+id/checkBox1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    style="?android:attr/starStyle"
    android:text="CheckBox" 
/>
Run Code Online (Sandbox Code Playgroud)


Dha*_*mar 5

检查下面的代码它可能会帮助你...

在您的布局文件中,您的复选框...

<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"/>
Run Code Online (Sandbox Code Playgroud)

在 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>
Run Code Online (Sandbox Code Playgroud)