Res/values/color. xml
<? XML version ="1.0"Encoding ="UTF-8"?> <Resources> <color name ="Green"># Ff00ff00 </color> </resources>
Res/drawable/mail. xml
<? XML version = "1.0" encoding = "UTF-8" ?> < Linearlayout Xmlns : Android = Http://schemas.android.com/apk/res/android" Android : Orientation = "Vertical" Android : Layout_width = "Fill_parent" Android : Layout_height = "Fill_parent" > < Textview Android : Layout_width = "Fill_parent" Android :Layout_height = "Wrap_content" Android : Text = "@ String/hello" Android:ID="@ + ID/TV" /> </ Linearlayout >
Src/ext03_04.java
package gphone. ex03_04; import android. app. activity; import android. content. res. resources; import android. OS. bundle; import android. widget. textview; public class ex03_04 extends activity {/** called when the activity is first created. * // @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); resources Resources = This. getbasecontext (). getresources (); int Green = resources. getcolor (R. color. green); textview TV = (textview) This. findviewbyid (R. id. TV); TV. settextcolor (green); }