如何获取TextView的背景颜色?

OrS*_*nik 10 android textview

如何获取TextView的背景颜色?

当我按TextView时,我想根据正在使用的背景颜色更改背景颜色.

TextView没有如下方法:

getBackgroundResource()
Run Code Online (Sandbox Code Playgroud)

编辑:我更喜欢获得背景颜色的resId.

Gok*_*rik 16

如果你想获得背景的颜色代码,试试这个:

if (textView.getBackground() instanceof ColorDrawable) {
    ColorDrawable cd = (ColorDrawable) textView.getBackground();
    int colorCode = cd.getColor();
}
Run Code Online (Sandbox Code Playgroud)