1、使用Color类的静态方法argb创建颜色
int color = Color.argb(127, 255, 255, 255);
2、把16进制颜色值转换为int类型数值
int color = Color.parseColor("#FFD71E06");
3、使用xml资源文件来表示颜色
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
使用方法:
java
textView.setTextColor(getResources().getColor(R.color.colorPrimary));//已过时
textView.setTextColor(ContextCompat.getColor(this, R.color.colorPrimary));//替换方法
xml
android:textColor="@color/text_color_white"
android:background="@drawable/full_background"