第一种方式很简单,用于静态或初始文字颜色的设置,方法如下:



main.xml





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"
android:background="@drawable/white"
>
<TextView
android:id="@+id/tv01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:autoLink="all"
android:textColor="@color/red"
/>
</LinearLayout>

<?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"
android:background="@drawable/white"
>
<TextView
android:id="@+id/tv01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:autoLink="all"
android:textColor="@color/red"
/>
</LinearLayout>




color.xml





Xml代码
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="red">#FF0000</color>
</resources>

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="red">#FF0000</color>
</resources>




drawable.xml





Xml代码
<?xml version="1.0" encoding="utf-8"?>
<resources>
<drawable name="white">#FFFFFF</drawable>
<drawable name="dark">#000000</drawable>
<drawable name="red">#FF0000</drawable>
</resources>

<?xml version="1.0" encoding="utf-8"?>
<resources>
<drawable name="white">#FFFFFF</drawable>
<drawable name="dark">#000000</drawable>
<drawable name="red">#FF0000</drawable>
</resources>




strings.xml





Xml代码
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">地址:http://yahaitt.iteye.com</string>
<string name="app_name">丫梨的笔记本</string>
</resources>

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">地址:http://yahaitt.iteye.com</string>
<string name="app_name">丫梨的笔记本</string>
</resources>






上面将资源部分分成了3个部分,目的是为了清晰,当然你也可以只建一个xml文件放在res目录下,而且文件名称可以随便命名。



注意两个地方:

1、main.xml的TextView标签中:

android:textColor="@color/red"

2、color.xml中:

<color name="red">#FF0000</color>



@color指获取资源文件中(所有res目录下的xml文件)的<color>标签

/red指在标签下找其name值为red的内容,此时其值为#FF0000



因此,这里我们还可以这样做:

android:textColor="@drawable/red"


@drawable指获取资源文件中<drawable>标签

/red指在标签下找其name值为red的内容



以此类推,相信你也就知道了如果是在strings.xml中该怎么做了。

更多相关文章

  1. Android实现文件上传功能(接收端用strust2)
  2. android 获取文件的扩展名和去掉文件的扩展名
  3. android平台上的文件下载,文件和文件的操作
  4. Android 代码质量工具集成与应用
  5. Android APK文件安装过程小结
  6. adb命令执行java代码
  7. Android 文件操作
  8. android从资源文件中读取文件流显示

随机推荐

  1. Google I/O 发布android studio for linu
  2. 使用GCM服务(Google Cloud Messaging)实现A
  3. android设置软键盘搜索键以及监听搜索键
  4. Android上webview界面切换动画效果
  5. Android学习之BottomNavigationBar实现An
  6. Andriod ADB Interface驱动安装失败Confi
  7. Android Studio 安装 NDK(Mac OX)
  8. Android中Fragment的使用
  9. android内存分析工具- MAT的初识(1)
  10. 如何在Android Studio使用Java8 Lambda表