我正在 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/