在视图显示中使用Theme

在视图显示中使用Style中,使用的是针对一个视图指定元素的样式。如果要针对整个Activity,对它的背景颜色和字体等做统一的样式约定,就需要使用另外一个技术,theme。

以下示例就是在在视图显示中使用Style基础上增加了theme。

image

首先,要编写theme文件,和style文件类似,是放在res/values目录下:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="custom_background_color">#FFFFFFFF</color>
    <style name="RiverTheme" parent="android:Theme.Light">
        <item name="android:windowBackground">@color/custom_background_color</item>
    </style>
</resources>

 

这里继承了系统的theme.light,一般theme是继承的,这样可以对默认的风格不必重复定义。

本例定义了一个背景色。这里背景色要单独声明,不能在item元素中直接写颜色值,会提示语法错误。

引用该theme,在manifest文件中指定的Activity中:

<activity android:name=".ListViewActivity" android:label="@string/app_name"
   android:theme="@style/RiverTheme">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

源代码见:

http://easymorse.googlecode.com/svn/tags/CustomListViewDemo-0.3/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值