如何获取 TextView 的背景颜色? [英] How do I get the background color of a TextView?
本文介绍了如何获取 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屋!
查看全文