【问题标题】:How to make selection highlight of list rows with different colors?如何使不同颜色的列表行的选择突出显示?
【发布时间】:2014-10-04 21:32:48
【问题描述】:

我有一个问题。

如何在列表视图中以不同的颜色突出显示行?但我想用列表选择器来做正确的事情。

请提供一些简单的颜色

谢谢

【问题讨论】:

    标签: android listview selector


    【解决方案1】:

    您可以在 Adapter.getView() 方法中设置颜色:

    public View getView(int position, View convertView, ViewGroup parent) {
        View result = ...
        // check convertView, inflate new layout, bla-bla-bla
    
        if (position % 2 == 0) {
            result.setBackgroundResource(R.drawable.even);
        } else {
            result.setBackgroundResource(R.drawable.odd);
        }
    
        return result;
    }
    

    【讨论】:

    • 偶数和奇数...是选择器吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-07
    • 2018-03-12
    • 2013-02-18
    • 1970-01-01
    • 2014-01-18
    • 2021-09-09
    • 1970-01-01
    相关资源
    最近更新 更多