获取listview中所选行的背景颜色

时间:2017-02-20 09:02:33

标签: android listview background-color

我必须以编程方式获取listview中所选行的背景颜色。 我写这个来为行着色:

View v;    
v.setBackgroundColor(context.getResources().getColor(R.color.childArticle));

但是我无法弄清楚如何获得行的颜色,因为我必须做这样的事情:

colorOfSelectedRow = v.getBackgroundColor();
if(colorOfSelectedRow == MY_COLOR) {
    // Do something
}

谢谢!

编辑: 我想知道按下的行的颜色,但不是所有的行都用相同的颜色着色!

3 个答案:

答案 0 :(得分:1)

您可以在Tag中设置背景颜色ID,如下所示,也可以获取color.xml中提到的颜色ID

首先将颜色代码ID设置为标记。

view.setTag(R.color.childArticle);

然后当你想从视图中获取背景颜色获取标记并解析其值并从color.xml文件中获取颜色代码。

int ColorId = Integer.parseInt(view.getTag().toString());

答案 1 :(得分:0)

此代码将输出单击行的颜色字符串,如果没有设置颜色背景,则输出任何内容。但是你没有具体说明你如何设置背景颜色。

<MapView.Marker
     coordinate={{
         latitude: this.props.latitude,
         longitude: this.props.longitude,
     }}
     importantStatus={{
         isImportant: false,
         unimportantOpacity: 0.5,
     }}
     // isImportant: false
     // unimportantOpacity: 0.5
>
</MapView.Marker>

答案 2 :(得分:0)

 Could not find a version that satisfies the requirement python-openstackclien
 (from versions: )
No matching distribution found for python-openstackclient

使用此..