改变一个TextView的文本颜色和背景文本、颜色、背景、TextView

2023-09-07 09:02:49 作者:塮绝/~↘勾对

我在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.