android - 如何在不使用android中的图像的情况下增加复选框边框

标签 android checkbox size width border

找到很多关于如何更改 1. 复选框颜色、复选框颜色等的问题/答案,但没有关于增加复选框边框(方形边框)的问题/答案。

下面是我的复选框 xml 代码

 <CheckBox
        android:id="@+id/mChkAgree"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_margin="10dp"
        android:buttonTint="@color/black"
        android:scaleX="1.70"
        android:scaleY="1.70"
        android:text="@string/agree_text"
        android:textColor="@color/black"
        android:textSize="14sp" />

现在复选框边框几乎不可见

enter image description here

那么如何增加方形复选框的边框(宽度)呢?

我也不想为复选框使用图像,所以可以不使用自定义图像吗?

最佳答案

根据这篇文章:http://www.techrepublic.com/blog/software-engineer/create-a-custom-checkbox-in-your-android-app/

增加正方形边框的最佳方法是使用带有自定义 android:drawable 标签的复选框。

自定义可绘制对象示例(放入/res/xml 文件夹)

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
 android:shape="rectangle">
<stroke android:width="4px"/>
<size android:height="20dp" android:width="20dp"/>
</shape>

还有……

<CheckBox
    android:id="@+id/mChkAgree"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_margin="10dp"
    android:buttonTint="@color/black"
    android:scaleX="1.70"
    android:scaleY="1.70"
    android:text="@string/agree_text"
    android:textColor="@color/black"
    android:textSize="14sp" 
    android:drawable="@xml/custom_checkbox />

关于android - 如何在不使用android中的图像的情况下增加复选框边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38721853/

相关文章:

Android:克隆可绘制对象以使用过滤器制作 StateListDrawable

php - 从复选框将多个值存入 MySQL

ipad - 如何使用 "next"在 iPad 上选择复选框(vanilla html)?

c - 如何正确检查传递给 malloc() calloc() realloc() 的大小及其返回值?

c++ - 使用巨大 vector 卡住 C++ 程序

TCP 拥塞窗口大小

java - 处理从游标中提取公共(public)字段和特定于类型的字段的模式?

android - 找不到类 'android.widget.ThemedSpinnerAdapter' [Android Studio]

256x256 的 Android 设计图标

javascript - 为 div 中的所有复选框添加值、文本和状态到数组