【发布时间】:2023-04-02 18:36:01
【问题描述】:
所以我对 android 编程非常陌生,我有一个我完全无法解决的问题。
我想让我的文本背景变成我在基础教程中学习的红色。 但是,问题是当我更改背景颜色时,出现错误:
“渲染问题无法将红色转换为可绘制对象”
这是我在activity_main中编写的代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView
android:text="@string/hello_world"
android:background="red"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
这是我的 colours.xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="Red">#E60000</color>
</resources>`
我什至尝试将第 10 行更改为 android:background="@color/red
或android:background="color/red 甚至android:background="@android:color/red,但似乎没有任何效果。
有人能帮我解决这个问题吗?
【问题讨论】:
-
试试这个
android:background="#f00 -
也许你和*.com/questions/26618785/…有同样的问题
-
color name="Red"尝试使用color name="red"。资源名称区分大小写。并且必须全部小写。
标签: android xml colors background render