[英]android listactivity background color
How can I set the background color of a listactivity? 如何设置列表活动的背景颜色? I can set the background color of the listview items but not the hole Activity-View (see the black part on the bottom of the image).
我可以设置列表视图项的背景颜色,但不能设置活动视图的孔(请参见图像底部的黑色部分)。 How can I achieve that?
我怎样才能做到这一点?
The ListActivity XML looks like this: ListActivity XML如下所示:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:background="@color/darkbluelogo" >
<ImageView android:id="@+id/list_image"
android:layout_width="48dip"
android:layout_height="48dip"
android:contentDescription="@id/list_image"
/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"
android:background="@color/darkbluelogo"
android:scrollingCache="false"
android:cacheColorHint="#00000000" >
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@+id/title" >
</TextView>
<TextView
android:id="@+id/datetime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@+id/datetime" >
</TextView>
</LinearLayout>
</LinearLayout>
And that is how it appears on the device: 这就是它在设备上的显示方式:
SOLUTION: 解:
I had to add a style XML and add this to the activity in the AndroidManifest.xml 我必须添加样式XML并将其添加到AndroidManifest.xml中的活动
This was the correct answer: https://stackoverflow.com/a/10426474/1306012 这是正确答案: https : //stackoverflow.com/a/10426474/1306012
set layout_height
to fill_parent
in the xml file that contain your listview. 在包含listview的xml文件中将
layout_height
设置为fill_parent
。 and set background of that xml file what ever you want. 并根据需要设置该xml文件的背景。
EDIT : you can use theme to set background in this case 编辑 :在这种情况下,您可以使用主题设置背景
like this 像这样
<style name="MyTheme">
<item name="android:background">@color/darkbluelogo</item>
</style>
and apply this theme to your list activity in manifest file. 并将此主题应用于清单文件中的列表活动。
<activity
android:theme="MyTheme"
The following code shows how you can set the background colour of a ListActivity. 以下代码显示了如何设置ListActivity的背景颜色。
getListView().setCacheColorHint(Color.rgb(36, 33, 32));
getListView().setBackgroundColor(Color.rgb(36, 33, 32));
You Have given the height of your main linear layout 您已经给出了主线性布局的高度
android:layout_height="wrap_content"
make it 做了
android:layout_height="fill_parent"
it will change color of the whole background . 它会改变整个背景的颜色。
hi if u have used default android list view then add the following: 嗨,如果您使用默认的Android列表视图,然后添加以下内容:
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, CONTENT));
final ListView listView = getListView();
listView.setBackgroundColor(Color.parseColor("#4597CD"));
or if u have set listview in xml layout then: 或者如果你在xml布局中设置了listview,那么:
<ListView
android:id="@+id/listviewID"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#4597CD"
android:cacheColorHint="@color/darkbluelogo"
/>
check the ListView attribute width and height both should be "fill_parent".. 检查ListView属性的宽度和高度都应该是“fill_parent”..
<ListView
android:id="@+id/listCategory"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/darkbluelogo"
android:cacheColorHint="@color/darkbluelogo"
/>
super.getListView().setBackgroundColor(getResources().getColor(R.color.red));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.