安卓listactivity背景颜色 [英] android listactivity background color

查看:145
本文介绍了安卓listactivity背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何设置一个listactivity的背景颜色? 我可以设置列表视图项目的背景颜色,但不是空穴的活动 - 视图(参见上的图像的底部的黑色部分)。我怎样才能做到这一点?

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?

在ListActivity XML看起来是这样的:

The ListActivity XML looks like this:

<?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:

解决方法:

我不得不添加一个样式XML和它添加到在AndroidManifest.xml活动

I had to add a style XML and add this to the activity in the AndroidManifest.xml

这是正确的答案: <一href="http://stackoverflow.com/a/10426474/1306012">http://stackoverflow.com/a/10426474/1306012

推荐答案

设置 layout_height FILL_PARENT 的XML包含您的列表视图文件。并设置你想要什么都该XML文件的背景。

set layout_height to fill_parent in the xml file that contain your listview. and set background of that xml file what ever you want.

修改:您可以使用主题,在这种情况下,设置背景

EDIT : you can use theme to set background in this case

像这样

<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"

这篇关于安卓listactivity背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆