下面的範例, 我仍是將 <color> 放在 strings.xml, 但你也可獨立另一個 xml 檔做為顏色定義檔:


Java 程式引用語法
R.color.colorName
this.getResources().getColor(R.color.colorName)
如: setTextColor( R.color.myBlue );
如: setTextColor( this.getResources().getColor(R.color.myBlue) );
XML 引用語法
@color/colorName
如: android:textColor="@color/myBlue"