您的位置:首页 > 其它

style and theme

2013-12-24 15:13 197 查看
今天想写一些关于主题和样式的博客,以方便记录学习的过程和以后的应用今天有个应用要把样式改成明亮的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"    ... />

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: