我有一个扩展列表视图,当特定的组被展开时,我想要改变该组的文字颜色。我尝试了很多方法,但没有找到解决办法。如果有解决方案,请告诉我。
getGroupView()
方法。其中一个参数是isExpanded
布尔值。只需使用该值来决定要设置的文本视图的颜色即可。以下是示例:@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
//...
}
@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 ;
}