[android]theme命名规
来源:互联网 发布:飞鱼网络电视 编辑:程序博客网 时间:2024/05/04 04:59
对于android项目,一般都需要自定义theme,好使整个android项目有自己独特的风格,不过现实中很多android项目theme和style都能够以命名都很混乱
为了保证清楚一般可以采取以后几个步骤:
1.style和theme分开为两个文件。
一般需要在values下面有两个文件,一个是styles.xml,themes.xml, 有个甚至还需要好几个,千万不要把style和theme写在一个文件里面,久而久之,那里面就混乱的不成样子了。
2.有个总的theme和他的basetheme。
假如我们要做一个AppTheme作为程序在theme会写在androidmanifest.xml里面的Application上面,那么我还需要一个base的theme,叫做AppBaseTheme,这个的作用就是为不同版本的android系统做适应,在版本14以前,应该继承Theme.light, 在14以后,应该继承Theme.holo.light,在21以后,就应该继承Theme.material.light。(不一定是light,但就是那个意思)。
比如values目录下的themes.xml下面
<!-- Base application theme, dependent on API level. This theme is replaced by AppBaseTheme from res/values-vXX/styles.xml on newer devices. --> <style name="AppBaseTheme" parent="android:Theme.Light"> <!-- Theme customizations available in newer API levels can go in res/values-vXX/styles.xml, while customizations related to backward-compatibility can go here. --> </style> <!-- Application theme. --> <style name="AppTheme" parent="AppBaseTheme"> <!-- All customizations that are NOT specific to a particular API-level can go here. --> </style>
在values-v14目录下themes.xml, 需要对AppBaseTheme进行重写:
<style name="AppBaseTheme" parent="android:Theme.Holo.Light"> <!-- API 14 theme customizations can go here. --> </style>在values-v21目录下,我们可能需要继承material的theme来适配最新最炫的material design
<style name="AppBaseTheme" parent="android:Theme.Material.Light"> <!-- API 21 theme customizations can go here. --> </style>
正确写法:
<style name="AppTheme.yourTheme"> </style>
错误写法1:
<style name="yourTheme" parent="AppTheme"> </style>错误写法2:
<style name="Theme.yourTheme" parent="AppTheme"> </style>
4.style规则和theme大致一样,但是应该指定parent为系统的wight的风格。
总结:第1,3条为主要关键,主要的rule没有了,就会越来越乱,加上团队上的每个人对于theme比较轻视,但是却对此认识不足,甚至有人认为做好了效果是对的,那个有什么不对的。但勿以恶小而为之,小细节也应整理清楚,才能导致代码悄悄的腐坏。
0 0
- [android]theme命名规
- android:theme
- android:theme
- android theme
- Android:theme
- android theme
- Android Theme
- android theme
- android:theme
- android Theme
- android:theme
- Android:theme
- Android Theme
- Android Theme
- android:theme
- android:theme
- Android theme
- Android Theme
- Contest - 2014常熟理工学院第四届软件大赛
- 土豆和西红柿根本就不是一个世界的但是他们走到了一起
- 对“剖析液晶屏逻辑板TFT偏压电路”一文的一点看法(下)
- poj 3254 Corn Fields(状压dp)
- C++学习笔记(第12章->类和动态内存分配)
- [android]theme命名规
- poj2288(状压dp)
- Mina工作原理分析
- sepl 3.0,全方位全能型计算机语言
- 最短路径算法对比分析
- 时空旅行的可能性(无聊研究社)
- 解决Qt For Android 识别不到手机 Incompatible devices 问题
- hdu3920(状压dp)
- Java:equals和hashCode的理解