繁体   English   中英

我在 main.xml 中设置的背景颜色在应用程序运行时未显示

[英]The background color I'm setting in main.xml isn't showing when the app runs

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

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

这是我的 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"
/>

这是主要活动中的 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));
}

有任何想法吗? 谢谢

这是我的字符串.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相同的文件夹中创建该文件。

除此之外,您还有一些错误:

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

@color/listViewBG更改为#FFFFFF看看屏幕是否更改 colors 这意味着您在 strings.xml 中声明它时出现问题。

http://developer.android.com/resources/samples/SoftKeyboard/res/values/colors.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM