如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
Android中的资源访问源码-----(基础版)1、颜色资源案例一:颜色资源的使用项目结构工程名Chapter03_resource_color包名Com.amaker.ch03.color应用程序名称TestColoractivityTestColorActivity项目代码:第一步:在res\values下新建一个color.xml<?xmlversion="1.0"encoding="utf-8"?><resources><colorname="red_text">#f00</color><colorname="blue_bag">#0000ff</color></resources>第二步:编辑res\layoutmain<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical"><TextViewandroid:text="测试颜色资源文件"android:textColor="@color/red_text"//引用颜色资源,在资源文件下引用的android:layout_width="fill_parent"android:layout_height="wrap_content"/></LinearLayout>第三步:改变程序的背景颜色编辑TestcolorActivity.javapackagecom.amaker.ch03.color;importandroid.app.Activity;importandroid.os.Bundle;publicclassTestcolorActivityextendsActivity{/**Calledwhentheactivityisfirstcreated.*/@Override//map键--值savedInstanceState:保存状态publicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);getWindow().setBackgroundDrawableResource(R.color.blue_bag);//改变背景颜色}}2、字符串资源案例二、字符串资源的使用项目结构工程名Chapter03_resource_string包名Com.amaker.ch03.string应用程序名称TeststringactivityTeststringActivity项目代码第一步:编辑res\valuesstrings.xml<?xmlversion="1.0"encoding="utf-8"?><resources><stringname="app_name">TeststringsResource</string><stringname="test_str1">从代码中引用</string><stringname="test_str2">从资源文件引用</string></resources>第二步:完成资源文件中引用字符串资源,编辑的main.xml<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical"><TextViewandroid:id="@+id/MyTextView01"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/test_str2"/>//资源中引用<TextViewandroid:id="@+id/MyTextView02"android:layout_width="fill_parent"android:layout