如何更改选定/集中的ListView项目的字体颜色? [英] how to change font color in selected/focused ListView items?

查看:153
本文介绍了如何更改选定/集中的ListView项目的字体颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我挣扎与此这显然是一个非常简单的效果,但令人难以置信没有找到任何intutitive方式做在Android的。

I am struggling with this which apparently is a very simple effect but incredibly haven't found any intutitive way for doing it in Android.

我有一个ListView和我设法使所选择的项目被通过获取新的背景绘制高亮显示,自定义背景图片。这个我也创造了新的风格,我设置了机器人:listSelector 属性指向一个 StateListDrawable ,我已指定其可绘制用于每个州

I have a ListView and I managed to customize the background images so the selected item gets highlighted by getting a new background drawable. This I do creating a new style where I set the android:listSelector attribute to point a StateListDrawable where I have specified which drawables to use for every state.

然而,每个ListView项是的Li​​nearLayout在那里我有两个TextViews。我的目标是能够改变,只要家长有选择或pressed这些孩子意见的文本颜色,在作为背景绘制做同样的时间。我知道有一个 Col​​orStateList 但一直没成功的设置,该设置了起来。

However each ListView item is a LinearLayout where i have two TextViews. My goal is to be able to change the text color of these child views whenever the parent is selected or pressed, at the same time as the background drawable does. I know there is a ColorStateList but haven't been succesful setting that up.

有没有人出头得到这样的工作吗?

Has anybody succeed getting something like this to work?

感谢。

推荐答案

这些都不是可能的答案,当你的ListView被泄露的布局,有多个视图。您需要设置你的孩子意见:

Neither of these are possible answers when your ListView is compromised of a layout that has multiple views. You need to set your child views to:

android:duplicateParentState="true"

现在,您可以使用他人上面所描述来声明TextViews'颜色使用选择,如方法:

Now you can use the methods others have described above to declare your TextViews' colors using a selector such as:

android:textColor="@drawable/my_row_selector"

和我敢肯定,你是知道的,但选择器可以非常简单,如:

and I'm sure you're aware, but the selector can be as simple as:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:color="@color/white" />
    <item android:color="@color/black" />
</selector>

正如你所看到的,@Color值是允许的。希望这有助于。

As you can see, @color values are allowed. Hope this helps.

另外 - 安卓STATE_ pressed用于与AdapterView.OnItemClickListener一起

Also - android:state_pressed is used in conjunction with the AdapterView.OnItemClickListener.

这篇关于如何更改选定/集中的ListView项目的字体颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆