android studio checkbox样式
时间: 2023-11-10 22:05:02 浏览: 139
在 Android Studio 中,可以通过修改 CheckBox 的样式来改变其外观。一种简单的方法是使用自定义 drawable。首先,在 res/drawable 目录下创建一个 XML 文件,例如 checkbox_custom.xml,然后在文件中定义 CheckBox 的样式,例如:
```
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/checkbox_checked" android:state_checked="true"/>
<item android:drawable="@drawable/checkbox_unchecked"/>
</selector>
```
其中,@drawable/checkbox_checked 和 @drawable/checkbox_unchecked 分别是 CheckBox 选中和未选中时的图片资源。接下来,在布局文件中使用该样式,例如:
```
<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/checkbox_custom"
android:text="CheckBox"/>
```
这里的 android:button 属性指定了 CheckBox 的样式为 checkbox_custom.xml 中定义的样式。运行应用程序后,CheckBox 的外观将根据自定义样式进行更改。
阅读全文
相关推荐














