android - Android 复选框
问题描述
我正在尝试使用具有以下布局配置的复选框。
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/gdprOptIn"
fontPath="fonts/AvenirNextRegular.ttf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="@dimen/medium_margin"
android:layout_marginTop="@dimen/medium_margin"
android:button="@drawable/checkbox"
android:checked="false"
android:paddingLeft="@dimen/default_margin"
android:text="@string/opt_in_gdpr"
android:textColor="@color/paper_ink_light"
android:visibility="gone"
android:gravity="top"/>
我找不到一种方法: - 避免文本可点击。我可以通过点击文本来选中/取消选中该框 - 在复选框周围添加圆形/方形轮廓,使其更易于使用。
任何想法 ?
解决方案
如果您不希望文本可点击,您可以将单个<CheckBox>
标签替换为<LinearLayout>
a<CheckBox>
和 a <TextView>
。例如,这个:
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello world"/>
可以用这个代替:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="hello world"/>
</LinearLayout>
如果您想在复选框周围绘制一个框以使其更加突出,您可以将其包裹在<FrameLayout>
带有彩色背景的 a 中:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#fac">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</FrameLayout>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="hello world"/>
</LinearLayout>
推荐阅读
- javascript - Javascript AzureAd 消费休息服务
- point-cloud-library - 当前对 CUDA for PCL 的开发支持
- java - 通过 xsd 创建 JAXB 类并获取类对象中 xml 的解组结果
- firebase - 可以在现场托管 Firestore?
- azure - 使用 az cli 创建工作项时如何添加标签
- python - 用来自另一列的值替换 NAN
- python - 如何在 jupiter-notebook 中运行 python 文件 .py?
- python - tfidf 在适合训练数据后如何转换测试数据?
- slack - 在 C# 中访问对话 API
- flutter - ChangeNotifier 应该使用“extends”还是“with”关键字?- 颤振