java - 更改 ExpandableListView 中每一行的背景颜色?

标签 java android

嘿,是否可以更改 ExpandableListView 中指定行的背景?我想要的是:第一行蓝色,第二行红色,第三行蓝色,第四行红色.....谢谢

最佳答案

是的,这是可能的,您必须为可扩展 ListView 使用自定义适配器。

 @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
            View convertView, ViewGroup parent) {
       //......
        //...... Your code for row view
       //.....

        //Now write here code for set colors for rows
        if(childPosition % 2 == 0) {
           convertView.setBackgroundColor("#0000FF"); // use this when you want to use hexa value of colors
        } else {
           convertView.setBackgroundColor("#FF0000"); // use this when you want to use hexa value of colors
        }

        //setBackgroundResource(android.R.color.transparent); // use this for predefined colors at place of setBackground


       return convertView;
    }

阅读this文章,此处还提供示例和源代码。

关于java - 更改 ExpandableListView 中每一行的背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5679538/

相关文章:

java swing GroupLayout - 如何交换组件的位置

Android AlarmManager 设置功能不起作用?

android - 如何在自定义游标适配器上实现稳定的 ID?

android - Twitter + OAuth 集成

java - 不完整父级上 Dagger .plus() 的回溯

Java exec() 不返回管道连接命令的预期结果

java - Native2Ascii API

javascript - 计算两个地理点之间的最短路径?

android - 是否可以在 Android 库项目中获取应用程序的上下文?

java - 为什么 Java String.format 的输出为 null Boolean false 以及如何将 String.format 改为 null?