java - 应用程序运行时,我在 main.xml 中设置的背景颜色没有显示

标签 java android

我正在 main.xml 中设置背景颜色。

当我在 Eclipse 中预览布局时,背景颜色显示正确,但当应用程序在我的设备上运行时,背景颜色默认为黑色。当应用程序运行时,我对 main.xml 的更改似乎没有反射(reflect)出来。

这是我的 main.xml 文件

<?xml version="1.0" encoding="utf-8"?>

<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/lst"
android:layout_width="match_parent"
android:background="@color/listViewBG"
android:divider="@drawable/divider"
/>

这是主 Activity 中的 OnCreate

public class AleWorldActivity extends ListActivity
{
String classes[] = { "Movies", "Pictures" };

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setListAdapter(new ArrayAdapter<String>(AleWorldActivity.this, android.R.layout.simple_list_item_1, classes));
}

有什么想法吗? 谢谢

这是我的 strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="hello">Hello World, AleWorldActivity!</string>
<string name="app_name">Ale World</string>
<color name="listViewBG">#e101f5</color>

</resources>

凯文

最佳答案

您应该在 colors.xml 上声明您的颜色。在 strings.xml 所在的同一文件夹中创建该文件。

此外,您还有一些错误:

  • 您缺少 setContentView(R.layout.main) AleWorld Activity 。
  • 您的ListView id 错误。将其更改为: android:id="@android:id/list
  • 在 ListView xml 中添加 android:layout_height="wrap_content"

关于java - 应用程序运行时,我在 main.xml 中设置的背景颜色没有显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10021259/

相关文章:

java - 识别最少使用的图标/文件/文件夹

java - Eclipse Juno 彩色代码折叠区域

javascript - Parse.com 设置用户角色

android - Dex 索引溢出异常 : Cannot merge new index 65772 into a non-jumbo instruction! : Jumbo Mode? 和/或 Multidex?幕后是什么?

android - View 边缘处的 float 操作按钮阴影剪裁

java - 在我的项目中构建和重用 android 开源 Dialer 源代码

java - 具有 100k 线程的基于 Java 的服务器能否生存

java - 搜索 jar 中的文件

java - Ant 使用 Manifestclasspath 运行 junit ClassNotFoundException

android - 使用 Retrofit 发布 soap xml 请求