展开列表时更改 ExpandedListView 中的文本颜色

发布于 2024-12-09 17:07:08 字数 68 浏览 4 评论 0原文

我有一个展开的列表视图,我想在展开特定组时更改组的文本颜色。我尝试了很多方法但无法找到解决方案。请告诉我是否有任何解决方案

I have a expandedlistview and I want to change the textcolor of group when the particular group is expanded. I tried many things but not able to find solution.Please let me know if there is any solution for this

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光清浅 2024-12-16 17:07:08

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

In the adapter you're using you should be overriding the getGroupView() method. One of the parameters you get is an isExpanded boolean value. Just use that value to decide what color to set the textview in question. Here is an example:

@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
    //...
}
邮友 2024-12-16 17:07:08

这是代码:

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

Here is code :

@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 ;
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文