样式(style)和主题(theme)(一)
来源:互联网 发布:数据库黑客大曝光 编辑:程序博客网 时间:2024/06/14 22:32
样式(style)和主题(theme)
一.样式资源
我们经常遇到需要对某个类型的组件指定大致相似的格式,比如字体、主题、背景颜色等
如果每次都要为view重复指定这些属性,无疑会有大量的工作量,而不利于项目后期的维护。
android样式就是提供包含一组格式,为一个组件设置某种样式。该样式所包含的全部格式将会应用于该组件。
Android的样式资源文件也放在/res/values目录下,样式资源文件的根元素是<resources.../>元素,该元素内可包含多个<style.../>子元素,每个<style/>元素定一个样式。<style/>元素指定如下两个属性。
1, name: 指定样式名称
2. parent: 指定样式所继承的父样式。当继承父样式,则继承所有父样式的全部格式,当然的当前样式可以覆盖父样式中的指定格式,这样方便,精简了,自定义样式。
在xml文件中调用方法如下:
@[package:]style/style_XXX
例子:
样式资源文件
\res\values\my_style.xml<resources> <style name="style1"> <item name="android:textSize">20sp</item> <item name="android:textColor">#00f</item> </style> <style parent="@style/style1" name="style2"> <item name="android:background">#ff0</item> <item name="android:padding">8dp</item> <item name="android:textColor">#000</item> </style></resources>
布局文件
\res\layout\activity_main.xml<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.styletest.MainActivity" > <TextView android:id="@+id/textView1" style="@style/style1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> <EditText android:id="@+id/editText1" style="@style/style2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView1" android:layout_below="@+id/textView1" android:layout_marginTop="23dp" android:text="你好哇" android:ems="10" > <requestFocus /> </EditText></RelativeLayout>
效果如下:
阅读全文
0 0
- 样式(style)和主题(theme)(一)
- 样式(style)和主题(theme)
- Android style(样式), theme(主题)资源
- 样式(style)和主题(theme)(二)
- 安卓 样式(Style)和主题(Theme)
- Android中的样式和主题(style & theme)
- 样式Style和主题Theme
- Android_主题(theme)与样式(style)
- Android_主题(theme)与样式(style)
- (4.1.20)android的样式(style)与主题(theme)
- 安卓(android)的样式(style)和主题(theme)
- Android样式(style)和主题(theme)资源介绍-android学习之旅(五十六)
- 风格style与主题theme(一)-style、theme的关系与使用
- Resource相关 风格style与主题theme(一)-style、theme的关系与使用
- android基础---样式和主题(style&theme)
- Android中的主题(theme)和样式(style)
- Android样式和主题(style&theme)
- android style(样式)和theme(主题)设置
- SpringMVC与Web解读(一):SpringMVC环境构建与ContextLoaderListener
- 多媒体文件管理-数据库external.db,internal.db (一)
- Effective Java其他碎片建议1
- qt creator 内存查看器
- MySql教程____mysql架构体系
- 样式(style)和主题(theme)(一)
- Spring4 之 AOP
- PAT甲级 1049. Counting Ones (30)
- 原生js实现倒计时
- Coursea吴恩达《卷积神经网络》课程笔记(2)深度卷积网络
- [saiku] 将saiku自带的H2嵌入式数据库迁移到本地mysql数据库
- C# 事件记录
- 认识WSGI
- ubuntu12 移植MP3