java - 我不能将放置在可绘制文件夹中的 .xml 文件用于我的应用程序的背景
问题描述
我想在我的应用程序中设计一个信息表单,但是当我使用我的自定义背景时,应用程序崩溃了。有人可以帮我解决它。
这是我的 .xml 代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:layout_margin="10dp"
android:gravity="center"
android:background="@drawable/main_activity_background" >
<LinearLayout
android:id="@+id/edittext_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="7"
android:hint="User Name"
android:textAllCaps="false" />
</LinearLayout>
<androidx.appcompat.widget.AppCompatButton
android:layout_width="match_parent"
android:layout_height="45dp"
android:text="Submit"
android:textAllCaps="false"
android:textSize="17sp"
android:background="@drawable/button_color"
android:textColor="@color/white"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:layout_below="@+id/devide_line" />
</RelativeLayout>
这是XML
与drawable相关的文件代码
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:endColor="#FAEBD7"
android:angle="180"
android:type="radial"/>
<corners
android:radius="300dp" />
</shape>
</item>
</selector>
解决方案
将您的可绘制 xml 代码包装在<layer-list>
标签中
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:endColor="#FAEBD7"
android:angle="180"
android:type="radial"
/>
<corners
android:radius="300dp"
/>
</shape>
</item>
<layer-list>
推荐阅读
- rest - 版本方法的 O365 REST API 错误响应
- c++ - 如何在 C++ 中修复 SFML“无法加载图像”?(垃圾字符)(解决)
- python - 在 numpy 矩阵上应用自定义函数
- java - 如何使用 GridBagLayout 在 Java Swing 中“模拟”一个 12 列网格
- sql - 如何从选择查询更新表中的列?
- javascript - 循环中的 HTTP 请求
- puppeteer - 如何从 ElementHandle 转到 DOM 元素
- django - 使用带多选的中间表与管理员的 Django M2M 关系问题
- c# - 创建一个名称为目录路径的新文件
- rest - Rest 或 RestQL 或 Falcor 或 GraphQl