今天想写一些关于主题和样式的博客,以方便记录学习的过程和以后的应用
今天有个应用要把样式改成明亮的Holo.Light的样式
<activity
android:theme="@style/activity_theme" // 这句是定义activity的主题
android:name=".ItemsActivity"
android:label="@string/app_name" >
主题又在res文件下的styles.xml中定义
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="activity_theme" parent="@android:style/Theme.Holo.Light"> // 这行是定义style为明亮的主题
</style>
</resources>
如
前面是引子,现在系统的根据andorid documents来整理styles 和 theme:
一:简介
style 是根据web的设计哲学,把样式和内容分开
举个例子,layout可以这样
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="#00FF00" android:typeface="monospace" android:text="@string/hello" />
或者是这样
<TextView style="@style/CodeFont" android:text="@string/hello" />
CodeFont在styles.xml中自己定义比如:
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="CodeFont" parent="@android:style/TextAppearance.Medium"> <item name="android:layout_width">fill_parent</item> <item name="android:layout_height">wrap_content</item> <item name="android:textColor">#00FF00</item> <item name="android:typeface">monospace</item> </style> </resources>
二:style的继承关系:
<style name="CodeFont.Red"> <item name="android:textColor">#FF0000</item> </style>这样CodeFont.Red就继承了CodeFont 并且加了颜色
三:style的属性:
<EditText android:inputType="number" ... />你可以把组件的属性设为是输入数字:
<style name="Numbers"> <item name="android:inputType">number</item> ... </style>在layout.xml中的EditText中就可以这样
<EditText style="@style/Numbers" ... />
本文介绍如何在Android应用中将样式更改为明亮的Holo.Light样式,并通过styles.xml文件进行定义。详细解释了style和theme的概念,以及如何在布局文件中应用样式。

被折叠的 条评论
为什么被折叠?



