我想在我的可扩展列表中对标题(即第一级项目)应用不同的颜色。我怎样才能做到这一点?
我在我的 Android 应用程序中使用以下类作为我的可扩展列表。
public class ExpandableListAdapter extends BaseExpandableListAdapter {...}
在其中,这是对 getGroupView() 函数的调用
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_group, null);
}
TextView lblListHeader = (TextView) convertView
.findViewById(R.id.lblListHeader);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(headerTitle);
return convertView;
}
我定义了我的 XML 布局,称为 list_group,如下所示。
<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="#ff9900" />
</LinearLayout>
如您所见,我将文本颜色指定为#ff9900。
但是,我想在列表视图中有一些标题为#ff9900 颜色,而其他标题为不同的颜色(例如红色)。
我如何使用布尔变量根据我想要的项目颜色加载不同的 XML 布局?
非常感谢。