如何在Android中更改ExpandableListView的背景颜色?

时间:2014-02-13 07:50:30

标签: android xml background expandablelistview

我的问题的标题几乎总结了我想要问的内容所以在描述中我将详细描述我的问题。

所以我有一个ExpandableListView,它在屏幕上打印成黑色,里面有白色文字。当我按下列表时,它会被消耗,我可以在其中选择详细信息。它看起来像这样:

|--------------------------|
|black color               | 
|   Title text(in white)   |
|                          |
|__________________________|
|  Item 1  (black text with white background)
|  Item 2                  |
|  Item N...               |

所以我的问题是如何更改“文本标题”内部的背景颜色,并对标题中显示的符号数量进行限制?

以下是我的XML文件:

    <ScrollView
    android:layout_width="fill_parent"
    android:layout_height="228dp" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#f4f4f4"
        android:orientation="vertical" >

        <ExpandableListView
            android:id="@+id/lvExp"
            android:layout_width="match_parent"
            android:layout_height="485dp"          >
        </ExpandableListView>
    </LinearLayout>
    </ScrollView>

项。 XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="55dip"
android:orientation="vertical" >

 <TextView
    android:id="@+id/lblListItem"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="17dip"
    android:paddingTop="5dp"
    android:paddingBottom="5dp"        
    android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft" />


</LinearLayout>    

Group.XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp"
android:background="#000000">


<TextView
    android:id="@+id/lblListHeader"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
    android:textSize="17dp"        
    android:textColor="#f4f4f4" 
    android:background="#323232"/>//this only changes some part of the background just around the text ONLY

</LinearLayout>

2 个答案:

答案 0 :(得分:1)

在textview中尝试这些属性:

<TextView 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:maxLines="1" 
    android:maxLength="10" 
    android:ellipsize="marquee"/>

答案 1 :(得分:0)

在expandablelistadapter中: 在

下的getGroupView中
  if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this.mContext
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.listheader, null);
        }

:把这个:

 convertView.setBackgroundColor(Color.parseColor("#FFFFFF"));

并限制XML中使用的文本标题字符:

<TextView 
android:id="@+id/secondLineTextView" 
android:layout_width="wrap_content"
android:layout_height="wrap_content" 
android:maxLines="1" 
android:maxLength="10" 
android:ellipsize="end"/>
相关问题