android - 如何制作一个看起来像这样的首选项屏幕?
解决方案
您可以在 Drawable 目录中创建一个custom_background.xml
,如下所示:
右键单击可绘制目录->新建->可绘制资源文件->输入文件名(这里是 custom_background)并在根元素中选择/输入“形状”。
现在在你的custom_background.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#2196f3" />
<corners android:radius="10dp" />
</shape>
您还可以在custom_background.xml
.
现在对于每个首选项,您可以在主布局下有一个单独的 ConstraintLayout(或您正在使用的任何其他布局),然后按如下方式提供该首选项布局custom_background.xml
的background
属性:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:padding="4dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/your_preference_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:background="@drawable/custom_background">
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
main_layout
根据您想要的外观进行填充。
让我知道这是否能解决您的问题。
推荐阅读
- python-3.x - 创建动态帧并递归存储它们
- php - 根据 2 个日期之间的天数从 SQL 中提取数据
- smarty - 在 Prestashop 的订单确认页面上创建指向外部页面的链接
- python - “外部范围的阴影名称是错误的”吗?
- r - 循环遍历文件夹中的 tif 文件,但不包括 R 中的 tif.aux 文件
- wpf - TextAnnotation 显示 ibeam 光标,已将 CanEditText 设置为 true,但不允许编辑
- r - 提取r中列表内的一组矩阵的最小矩阵
- excel - 如何在 powerpoint 中创建动态超链接?
- tensorflow - Tensorflow 数据集 API:将 tf.data.Dataset.from_generator 与 parallel_interleave 并行化
- python - 嵌入字符串中的模糊匹配字符串