Java Android应用程序背景颜色未设置

Java Android应用程序背景颜色未设置,java,android,Java,Android,我最近开始开发Android应用程序。我不是一个编程高手,我从2009年就开始用Java编程,但这是我的第一个Android应用程序。我试着按照一些教程来设置背景色,但对我来说根本不起作用。我不知道我做错了什么 在我的布局目录中,有名为main.xml和view_fact.xml的文件。它们都使用线性布局,我的LinearLayout标记如下所示: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android

我最近开始开发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”目录I中,“strings.xml”的内容是:


事实
#E8E8E8
但是背景色不会改变默认的黑色

我还尝试在我的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/color\u name您必须创建一个color.xml文件,然后才能以您尝试使用它的方式访问它

请原谅一些明显的问题,但是:您是否在Activity onCreate中调用setContentView(R.layout.main)?布局中是否有其他东西填充线性布局并覆盖背景灰色?

查看,我认为您需要在开始时删除
行。Eclipse不会在布局中使用该xml根构建新创建的应用程序

虽然这很奇怪,因为我在Android开发者网站()上找到的前两个例子包括它

我很想知道如果你去掉那条线会发生什么


在Eclipse中,如果我使用

<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="#E8E8E8"
>
并将布局声明为

<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"
>

然后背景也会改变


如果它对你来说表现不一样,那么会有一些古怪的事情发生,或者你使用的是与上面简单示例不同的布局,并且,好吧,在该布局中会有一些古怪的事情发生。

好的,我尝试了很多不同的方法来设置背景颜色,但没有一种有效。我现在遇到了文本不更新的问题。所以我要试着重新制作它。使用eclipse,如果还有问题,我会提出一个新问题。谢谢你的建议

如果您想使用@color/background\u grey,我相信您需要创建一个color.xml文件。否则,您可以使用android默认设置来检查。。。请看这个问题,将布局颜色更改为@android:color/white,然后从那里开始。另外,您在哪里使用您的视图和事实?你的主视图中只有线性布局?我现在尝试将布局颜色更改为该颜色。是的,view_事实上是另一个页面,当点击一个按钮时,它会将内容视图更改为该页面。我刚刚尝试在main.xml中设置:android:background=“@android:color/white”,但它仍然没有更改背景颜色。线性布局中有什么?有没有可能有什么东西阻挡了线性布局的背景?我一直使用这样的颜色引用,但没有特定的color.xml文件。如果按照strings.xml.No中的定义进行定义,它们可以正常工作。这不是问题所在。我尝试将我的颜色定义移动到color.xml,但仍然没有成功。谢谢你的建议。不,我错了。看到我的答案,但也告诉我们在我调用的onCreate方法中文件名是任意的:setContentView(R.layout.main);您正在使用Eclipse吗?如果打开布局文件,应该能够切换到“图形布局”选项卡,并查看背景颜色是否正确设置。如果你在那里看到了正确的颜色,那么可能还有其他事情在发生。是的,这仍然有效。我也尝试过以编程方式设置它,有什么建议吗?你能添加完整的布局文件吗?更新,我在eclipse中对此没有问题。
<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="@string/background_grey"
>
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="background_grey">#E8E8E8</color>
</resources>
<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"
>