<?xml version="1.0" encoding="utf-8"?> <resources> <color name="red_bg">#f00</color> <color name="blue_text">#0000ff</color> </resources>
<?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:text="测试颜色资源,红色背景,蓝色文字" android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/blue_text" /> </LinearLayout>
public class TestColorActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.test_color); // 引用颜色资源,设置背景色为红色 getWindow().setBackgroundDrawableResource(R.color.red_bg); } }