当ExpandedListView展开时,更改文本颜色

3
我有一个扩展列表视图,当特定的组被展开时,我想要改变该组的文字颜色。我尝试了很多方法,但没有找到解决办法。如果有解决方案,请告诉我。
2个回答

5
在您使用的适配器中,您应该重写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
    //...
}

我知道textView.setTextColor(/ 一些其他颜色 /);是解决方案,但对我没有起作用。我不明白为什么它不起作用。 - Sachchidanand

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 ;
        }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接