改变statelistdrawable文本颜色android的按钮 [英] change statelistdrawable text color android button

查看:301
本文介绍了改变statelistdrawable文本颜色android的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Android应用程序

I'm developing android application

我对按钮的每个状态不同的背景绘制和文本颜色(pressed,正常)

I have a different background drawable and text color for each status of the button (pressed , normal)

我创建statelistdrawable对象可以添加背景绘制,但现在我的问题是如何设置文本颜色

I have created statelistdrawable object to be able to add the background drawable , but my problem now is how to set the text color

任何一个可以帮助吗?

推荐答案

按钮是一个TextView,你可以调用<一个href=\"http://developer.android.com/reference/android/widget/TextView.html#setTextColor%28android.content.res.ColorStateList%29\"><$c$c>button.setTextColor(someColorStateList)在一个TextView。

Button is a TextView and you can call button.setTextColor(someColorStateList) on a TextView.

下面是如何做到这一点编程方式:

Here is how to do it programmatically:

   ColorStateList colorStateList = new ColorStateList(
            new int[][]{
                    new int[]{R.attr.state_pressed},
                    new int[]{R.attr.state_selected},
                    new int[]{-R.attr.state_selected},
            },
            new int[]{
                    Color.GREEN,
                    Color.BLUE,
                    Color.RED});
    TextView textView = ... some textView or button
    textView.setTextColor(colorStateList);

您当然可以做同样的xml配置(定义 colorStateList在XML 并与按钮的文字颜色属性相关联机器人:文字颜色=@绘制/ mycolorstatelist

You can of course do the same with xml configuration (define your colorStateList in xml and associate it with the button text color property android:textColor="@drawable/mycolorstatelist"

这篇关于改变statelistdrawable文本颜色android的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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