目前比较流行的主题样式 (4.0以后的主题)
AppTheme
Theme.AppCompat
例如:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<style name="AppTheme.NoActionBar">
来源(由来):
Hoho Theme
在4.0之前Android可以说是没有设计可言的,在4.0之后推出了Android Design,从此Android在设计上有了很大的改善,而在程序实现上相应的就是Holo风格,所以你看到有类似Theme.Holo.Light、 Theme.Holo.Light.DarkActionBar 就是4.0的设计风格,但是为了让4.0之前的版本也能有这种风格怎么办呢?这个时候就不得不引用v7包了,所以对应的就有Theme.AppCompat.Light、Theme.AppCompat.Light.DarkActionBar,如果你的程序最小支持的版本是API14(即Android 4.0),那么可以不用考虑v7的兼容。
Material Design Theme
Android在5.0版本推出了Material Design的概念,这是Android设计上又一大突破。对应的程序实现上就有Theme.Material.Light、Theme.Material.Light.DarkActionBar等,但是这种风格只能应用在在5.0版本的手机,如果在5.0之前应用Material Design该怎么办呢?同样的引用appcompat-v7包,这个时候的Theme.AppCompat.Light、Theme.AppCompat.Light.DarkActionBar就是相对应兼容的Material Design的Theme。
普及theme和style知识
项目中经常使用style和Theme,但却从来没有考虑过它们的区别,只会copy来copy去的,有时候还有些迷茫,为了彻底告别迷茫,现把这两者的区别和使用总结出来,供自己和大伙参考
一.作用域
Theme是针对窗体级别的,改变窗体样式。
Style是针对窗体元素级别的,改变指定控件或者Layout的样式
二.使用方式
Theme
1. 在res\values\ 下创建themes.xml或者styles.xml文件
2. 添加节点(根节点)
style
1 在AndroidManifest.xml文件中,为Activity指定theme属性(推荐) 就只直接在activity上指明主题 ,而不是res\values\styles或者themes下面
2 Activity创建时调用setTheme函数 (必须在setContentView前调用 )
android:theme="@android:style/Theme.Dialog" //将一个Activity显示为能话框模式
android:theme="@android:style/Theme.NoTitleBar" //不显示应用程序标题栏
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" //不显示应用程序标题栏,并全屏
android:theme="@Theme.Light" //背景为白色
android:theme="Theme.Light.NoTitleBar" //白色背景并无标题栏
android:theme="Theme.Light.NoTitleBar.Fullscreen" //白色背景,无标题栏,全屏
android:theme="Theme.Black" //背景黑色
android:theme="Theme.Black.NoTitleBar" //黑色背景并无标题栏
android:theme="Theme.Black.NoTitleBar.Fullscreen" //黑色背景,无标题栏,全屏
android:theme="Theme.Wallpaper" //用系统桌面为应用程序背景
android:theme="Theme.Wallpaper.NoTitleBar" //用系统桌面为应用程序背景,且无标题栏
android:theme="Theme.Wallpaper.NoTitleBar.Fullscreen" //用系统桌面为应用程序背景,无标题栏
android:theme="@style/Theme.AppCompat.NoActionBar" 黑色背景
android:theme="@style/AppTheme.NoActionBar" 白色背景