扩展列表时,在ExpandedListView中更改文本颜色

时间:2011-10-14 09:47:27

标签: android expandablelistview

我有一个扩展列表视图,我希望在扩展特定组时更改组的文本颜色。我尝试了很多东西但是找不到解决方案。如果有任何解决方案,请告诉我。

2 个答案:

答案 0 :(得分:5)

在您使用的适配器中,您应该覆盖getGroupView()方法。您获得的参数之一是isExpanded布尔值。只需使用该值来确定要设置textview的颜色。这是一个例子:

@Override
public void getGroupView(int groupPosition, boolean isExpanded,
        View convertView, ViewGroup parent) {
    // Here you would do your convertView initialization
    // ...
    TextView textView = (TextView) convertView.findViewById(R.id.textview);
    if(isExpanded)
        textView.setTextColor(/* some color */);
    else
        textView.setTextColor(/* some other color */);
    // Do the rest of your view binding
    //...
}

答案 1 :(得分:0)

这是代码:

@Override
        public View getGroupView(int groupPosition, boolean isExpanded,
                View convertView, ViewGroup parent) {
            View parentView = ( View )convertView.findViewById( R.id.settings_menu );
            parentView.setBackgroundResource( R.drawable.background1 );

            TextView parentTextView = ( TextView )convertView.findViewById( R.id.menu_title );
            parentTextView.setText( groups[ groupPosition ].toString() );

            if( isExpanded ){
                convertView.setBackgroundResource( R.drawable.settings_background2 );
                parentTextView.setTextColor( R.color.black);
            }

            return convertView ;
        }