现在的位置: 首页 > 综合 > 正文

android样式

2018年04月19日 ⁄ 综合 ⁄ 共 929字 ⁄ 字号 评论关闭
Android中可以这样定义样式:
一、添加样式
在res/values/styles.xml文件中添加以下内容
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name=“itcast”> <!--
为样式定义一个全局唯一的名字-->
        <item name=“android:textSize”>18px</item>
<!-- name属性的值为使用了该样式的View控件的属性 -->
        <item name="android:textColor">#0000CC</item>
    </style>
</resources>
在layout文件中可以像下面这样使用上面的android样式:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" ....>
    <TextView style="@style/itcast"
        .....  />
</LinearLayout>
 
二、样式的继承
<style>元素中有一个parent属性。这个属性可以让当前样式继承一个父样式,并且具有父样式的值。当然,如果父样式的值不符合你的需求,你也可以对它进行修改,如下:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="itcast">
        <item name="android:textSize">18px</item>
<!-- name属性为样式要用在的View控件持有的属性 -->
        <item name="android:textColor">#0000CC</item>
    </style>
    <style name="subitcast"
parent="@style/itcast"
>
        <item name="android:textColor">#FF0000</item>
    </style>
</resources>

抱歉!评论已关闭.