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);
}
}