android - Android 中 CheckBox 右侧的文本

标签 android android-layout checkbox

我正在尝试模仿手机“设置”应用中的 CheckBox。 它看起来像这样: CheckBox in my Galaxy S4 5.0.1 Settings app

我试过使用单独的 TextView,但那样的话只有复选标记是可点击的,而不是文本和复选标记。
有办法实现吗?
我还尝试了 CheckedTextView 但找不到要使用的正确 drawable。

最佳答案

据我所知这是可行的

<?xml version="1.0" encoding="utf-8"?>
<CheckBox xmlns:android="http://schemas.android.com/apk/res/android"
    android:text="Text"
    android:layout_width="match_parent" 
    android:layout_height="match_parent"
    android:button="@null"
    android:drawableRight="?android:attr/listChoiceIndicatorMultiple"/>

使用 android:button="@null" 删除标准复选框按钮/图像,然后将复选框图像添加为右侧可绘制对象(或使用 drawableEnd 支持 RTL)

android:drawableRight="?android:attr/listChoiceIndicatorMultiple"

关于android - Android 中 CheckBox 右侧的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30233903/

相关文章:

android - 工具栏重叠在状态栏下方

javascript - 在 React JS 中设置复选框值

Java:最佳实践 - 回调与成员类

javascript - 如何在 Javascript 或 Jquery 中设置 "backspace press"事件的监听器?

java - 布局中的空指针异常

带有内置登录 View 和身份验证表单的 Django "Remember Me"

android - 当复选框改变状态时如何做某事?

android - 在 Fragment 中创建图像的 GridView

android - 膨胀类 android.support.design.internal.BottomNavigationView 时出错

android - 如何将阴影叠加到 ScrollView 上?