【发布时间】:2012-09-24 19:54:49
【问题描述】:
我最近开始开发一款 Android 应用。我不是编程菜鸟,自 2009 年以来我一直在使用 Java 编程,但这是我的第一个 Android 应用程序。我已经尝试遵循一些关于如何设置背景颜色的教程,但它根本不适合我。我无法弄清楚我做错了什么。
在我的布局目录中,我有名为 main.xml 和 view_fact.xml 的文件。他们都使用线性布局,我的 LinearLayout 标签如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/background_grey"
>
在我的“values”目录中,“strings.xml”的内容是:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Facts</string>
<color name="background_grey">#E8E8E8</color>
</resources>
但是背景颜色并没有从默认的黑色改变。
我也尝试在我的 AndroidManifest.xml 文件中添加:“android:theme="@android:style/Theme.Light"”。
这些都不行,有什么建议吗?
谢谢。
在我的 view_fact.xml 页面上,它看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/background_grey"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Fact:"
android:padding="10dp"
android:textColor="#080808"
/>
<TextView
android:id="@+id/factData"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text=""
/>
<Button
android:id="@+id/anotherFactButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Another Fact"/>
</LinearLayout>
有趣的是,“factData”中的文本是灰色的,而上面的文本视图中的文本:“Fact:”是白色的,我尝试将其颜色更改为红色,但它不起作用。它保持白色。
有什么建议吗?我仍然没有设法让这个工作;谢谢。
【问题讨论】:
-
如果你想使用@color/background_grey,我相信你需要制作一个color.xml文件。否则你可以使用 android 默认值来检查...看到这个问题stackoverflow.com/questions/3769762/…
-
将布局颜色更改为 @android:color/white 并从那里开始。另外,你在哪里使用你的 view_fact?你的 main 中只有那个 LinearLayout 吗?
-
我现在尝试将布局颜色更改为该颜色。是的,view_fact 是另一个页面,当单击按钮时,它会将内容视图更改为该页面。
-
我刚刚尝试在 main.xml 中设置:android:background="@android:color/white" 但它仍然没有改变背景颜色。
-
线性布局里面有什么?是不是有什么东西挡住了线性布局背景?