//getBaseContext() 获得基础 Context
//getResources() 获得资源
Resources myColor=getBaseContext().getResources();
// 由资源 myColor 来获得 Drawable R.color. lightgreen 是颜色值的 ID 引用
Drawable color_M=myColor.getDrawable(R.color. lightgreen );
// 设置背景
text.setBackgroundDrawable(color_M);  //text为文本名

//利用 android.graphics.Color 的颜色静态变量来改变文本颜色
text_A.setTextColor(android.graphics.Color. GREEN );
//利用 Color 的静态常量来设置文本颜色
text_B.setTextColor(Color. RED );