style and theme

来源:互联网 发布:新丰网络问政首页 编辑:程序博客网 时间:2024/06/05 07:32

今天想写一些关于主题和样式的博客,以方便记录学习的过程和以后的应用

今天有个应用要把样式改成明亮的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"    ... />


0 0