Android :Style 的使用
来源:Linux 社区 作者:tsi annia n
Style 中文应该是式样,可以使用它指定 View 的外观,程序的主题等。下面是示例:
1. <?xml version="1.0" encoding="utf-8"?>
2. <LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"
3. Android:orientation="vertical"
4. Android:layout_width="fill_parent"
5. Android:layout_height="fill_parent"
6. >
7. <Button
8. Android:background="#ff00ffff"
9. Android:layout_width="fill_parent"
10. Android:layout_height="wrap_content"
11. Android:textColor="#ffff0000"
12. Android:textSize="18sp"
13. Android:text="Hello android"
14. />
15. </LinearLayo ut>
本来我们定义一个 View 对象是以这种方式进行的,现在我们应用 Style。
1. <?xml version="1.0" encoding="utf-8"?>
2. <LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"
3. Android:orientation="vertical"
4. Android:layout_width="fill_parent"
5. Android:layout_height="fill_parent"
6. >
7. <Button
8. style="@style/buttonstyle"
9. Android:text="Hello android"
10. />
11. </LinearLayo ut>
在 res/velues 目录下面新建一个 style.xml 的文件。文件名是任意的,不过必须要以.xml
结尾。
1. <?xml version="1.0" encoding="utf-8"?>
2. <resources>
3. <st yle name="buttonstyle" parent="@Android:style/TextAppearance.Medium">
评论1
最新资源