如何在Android中更改ExpandableListView的背景色?
我的问题的标题大致概括了我想问的问题,因此在描述中,我将详细描述我的问题 所以我有一个可扩展的列表视图,它以黑色打印在屏幕上,里面有白色文本。当我按下列表时,它被消耗,我可以选择列表中的详细信息。它看起来像这样:如何在Android中更改ExpandableListView的背景色?,android,xml,background,expandablelistview,Android,Xml,Background,Expandablelistview,我的问题的标题大致概括了我想问的问题,因此在描述中,我将详细描述我的问题 所以我有一个可扩展的列表视图,它以黑色打印在屏幕上,里面有白色文本。当我按下列表时,它被消耗,我可以选择列表中的详细信息。它看起来像这样: |--------------------------| |black color | | Title text(in white) | | | |_________________________
|--------------------------|
|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>
//这只会改变文本周围的部分背景
在textview中尝试以下属性:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:maxLength="10"
android:ellipsize="marquee"/>
在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"/>
您所说的“限制标题中显示的符号数量”是什么意思?例如,如果标题是“我喜欢吃肉”,屏幕上将显示“我喜欢吃…”添加TextView的android:singleLine=“true”属性,若要更改背景色,请为版面设置背景色,不适用于textviewNice这真的改变了背景颜色!非常感谢。但是符号的数量还是一样的:/Nice谢谢,最后一个问题是,在字符数减少后是否可以添加“…”?您正在设置限制,如果字符数不超过该限制,它将打印整个文本。您可以通过在java中重写onTextChanged事件并在文本末尾追加“…”来实现这一点