[Android]主题和样式
来源:互联网 发布:日本强大知乎 编辑:程序博客网 时间:2024/06/01 08:47
定义一个样式Style
创建:将xml文件保存在resource/values文件夹下的一个xml文件中,文件名随意,但是必须是.xml,并且根节点必须是
<Resoruces>
<resources> <style name="codeFont" > <item name="android:textColor">#ffffff</item> </style></resources>
继承
在<style>
中的parent属性可以让你继承其属性样式,并重写自己一些特有的属性。当然不仅可以继承系统的样式还可以继承自己定义过的样式。
如果是继承自己写的样式,还有一种方法不用写parent属性,用 . 来隔开表明继承关系。但是安卓自定义的样式不能通过这种方式进行继承。
<style name="codeFont" parent="@android:style/TextAppearance"> <item name="android:textSize">19sp</item></style>
在UI上应用样式和主题
有两种方式设置一个样式:
1. 为单个视图控件指定样式,在XML布局文件中的视图元素上添加style属性。
2. 为整个activity或者application指定样式,在manifest.xml中的<activity>
或者<application>
节点元素中添加 android:theme
属性。
(当为单个控件设置样式时,样式只会应用到这个控件,ViewGroup也是。但是当样式应用到Activity时、或者Application时,视图中所有的元素都将应用它支持的属性。)
选择一个平台支持的样式作为基础
有些主题是在高版本的android中出现的,比如有的主题是在5.0以上才能用。如果想用的话,考虑到兼容问题,我们就需要单独创建values-v21 的子文件夹在res目录下。然后在该文件夹下创建styles.xml文件。这样当运行在5.0以上的版本就会应用values-v21中主题。如果是低版本则运行默认res/values下的样式。
系统自带样式Android:theme.
查看文档的reference/android/R.style
android:theme=”@android:style/Theme.Dialog” 对话框
android:theme=”@android:style/Theme.NoTitleBar” 无标题栏
android:theme=”@android:style/Theme.NoTitleBar.Fullscreen” 不显示应用程序标题栏,并全屏
android:theme=”@android:style/Theme.Light” 背景为白色
android:theme=”@android:style/Theme.Light.NoTitleBar” 白色背景并无标题栏
android:theme=”@android:style/Theme.Light.NoTitleBar.Fullscreen” 白色背景,无标题栏,全屏
android:theme=”@android:style/Theme.Black” 背景黑色
android:theme=”@android:style/Theme.Black.NoTitleBar” 黑色背景,无标题栏
android:theme=”@android:style/Theme.Black.NoTitleBar.Fullscreen” 黑色背景,无标题栏,全屏
android:theme=”@android:style/Theme.Wallpaper” 用系统桌面为应用程序背景
android:theme=”@android:style/Theme.Wallpaper.NoTitleBar” 用系统桌面为应用程序背景,且无标题栏
android:theme=”@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen” 用系统桌面为应用程序背景,无标题栏,全屏
android:theme=”@android:style/Translucent” 透明主题
android:theme=”@android:style/Theme.Translucent.NoTitleBar” 无标题栏的透明主题
android:theme=”@android:style/Theme.Translucent.NoTitleBar.Fullscreen” 全屏模式的透明主题
android:windowContentOverlay 设置内容遮盖。当为null时,取消actionbar底部的阴影。如果是5.0以上的版本需要设置如下代码:
if(Build.VERSION.SDK_INT>=21){ getSupportActionBar().setElevation(0);}
- android 样式和主题
- android样式和主题
- android样式和主题
- Android样式和主题
- Android 样式和主题
- android 样式和主题
- android样式和主题
- android样式和主题
- android主题和样式
- android 主题和样式
- Android主题和样式
- android样式和主题
- Android:样式和主题
- Android 主题和样式
- Android样式和主题
- Android主题和样式
- [Android]主题和样式
- android样式和主题
- 学习Hadoop第十九课(Zookeeper集群搭建)
- libevent的event处理框架剖析
- ajax在兼容模式下失效的快速解决方法
- Android中的Service浅析
- Eclipse Neon 使用Git与Github 方法与问题
- [Android]主题和样式
- 使用WritePrinter打印图片
- redis持久化
- FlashBuilder 4.6 破解序列号和方法
- vs2010彻底解决 LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
- nodejs 异步编程 async
- 图片保存到数据库和从数据库读取照片
- 汇编语言编程中遇到的一个跨文件函数调用问题
- java中HashMap,LinkedHashMap,TreeMap,HashTable的区别