Android 更改扩展ListActivity的活动的背景图像

Android 更改扩展ListActivity的活动的背景图像,android,listview,android-layout,textview,android-linearlayout,Android,Listview,Android Layout,Textview,Android Linearlayout,我在以下地点学习了本教程: 并且能够成功运行应用程序。它主要使用名为list_item.xml的xml文件,其内容如下 <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" a

我在以下地点学习了本教程: 并且能够成功运行应用程序。它主要使用名为list_item.xml的xml文件,其内容如下

<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="24dp"
android:padding="6dp" />

这是应用程序首次启动时加载的第一个活动。我的要求是更改整个屏幕的背景视图。当我在xml文件list_item.xml中尝试android:background=@drawable/paperImage时,我能够更改列表中每一行的背景图像,而不是完整视图。有人能帮我吗?

您为listview指定了两种xml布局。1表示活动,另一个表示listview的一行。您应该为活动使用的布局设置背景,即放置在setContentView中的布局。现在您正在将背景图像设置为行xml文件。

只需在setListAdapter之后使用下面写的带有图像id的行,我希望这就是您想要的

ListView lv = getListView();
    lv.setCacheColorHint(0);
    lv.setBackgroundResource(R.drawable.myMainBackground);

在这里,您可以像setContentView一样设置contentview(r.layout.some_name);像这样吗?一开始我也很困惑,但在我在问题开头发布的教程链接中,作者提到:n TutListActivity.java,修改onCreate()方法以使用setListAdapter()方法加载数据。与常规活动不同,ListActivity不需要在整个活动只是ListView的情况下使用setContentView()。不,我只使用一个xml文件,其中只有一个textView元素。正如本教程中提到的,我正在从TutListActivity.java加载它:我只是想要Sam Janz上面所建议的。
ListView lv = getListView();
    lv.setCacheColorHint(0);
    lv.setBackgroundResource(R.drawable.myMainBackground);