如何获取TextView的背景颜色? [英] How do I get the background color of a TextView?

查看:347
本文介绍了如何获取TextView的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取TextView的背景颜色?

How do I get the background color of a TextView?

当我按下TextView时,我想根据使用的背景色来更改背景色.

When I press the TextView, I want to change the background color according to the background color that is in use.

TextView没有如下方法:

TextView does not have a method such as:

getBackgroundResource()

我希望获得背景色的resId.

I would prefer to get the resId of the background color.

推荐答案

如果要获取背景色代码,请尝试以下操作:

If you want to get color code of the background try this:

if (textView.getBackground() instanceof ColorDrawable) {
    ColorDrawable cd = (ColorDrawable) textView.getBackground();
    int colorCode = cd.getColor();
}

这篇关于如何获取TextView的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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