问题描述
我在Android开发完全以新的。
I am totaly new in Android development.
我试图改变FONTCOLOR和ListViewItem的背景,如果它`选择或pressed。
改变背景使用以下选择是绝对没有问题的:
I try to change the FontColor and the Background of ListViewItem if it`s selected or pressed.Changing the Background is absolutely no Problem by using following selector:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/background_pressed"></item>
<item android:state_focused="true"
android:drawable="@drawable/background_pressed"></item>
<item android:state_selected="true"
android:drawable="@drawable/background_pressed"></item>
<item android:drawable="@android:color/transparent"></item>
</selector>
但我怎么可以改变背景和FONTCOLOR?
But how can I change the Background and the FontColor?
推荐答案
更改的TextView的字体颜色以同样的方式作为列表项的的backgroundColor做:创建一个StateListDrawable并设置的TextView
的的android:文字颜色
您的自定义绘制
Changing the TextView's font color is done in the same way as the listitem's backgroundcolor: create a StateListDrawable and set the TextView
's android:textColor
to your custom drawable.
有关示例,请参见上点击 更改列表视图文本颜色。与你已经为列表项的背景结合这一点。
For an example, see Change ListViews text color on click. Combine this with what you already have for the listitem's background.
如果您想要的颜色褪色成海誓山盟,设定(例如)的android:exitFadeDuration =@安卓整数/ config_mediumAnimTime
在 &LT;选择方式&gt;
-tag
If you want the colors to fade into eachother, set (e.g.) android:exitFadeDuration="@android:integer/config_mediumAnimTime"
in the <selector>
-tag.
这篇关于改变一个TextView的文本颜色和背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!