1. 程式人生 > >【android】程式碼設定text的顏色setTextColor用法

【android】程式碼設定text的顏色setTextColor用法

【錯誤示範】
text用程式碼設定顏色setTextColor(R.drawable.selColor);
xml如下:
<drawable name="selColor">#c400ee</drawable>
顏色變成別的顏色了。
果斷召喚度娘。
原來不是這麼個用法啊啊啊啊!!!
【正解】
setTextColor((ColorStateList) mActivity.getResources().getColorStateList(R.drawable.selColor));