Android Theme 主题吧,这也算是大家可能都算不上熟悉的基础知识了,有时我们可能还会碰上 报 Theme 的错,所以大家最好都会 Android 的 Theme 做到如数家珍,真碰到问题时也知道怎么回事,要不先找真是挺费劲的
系统自带主题如下:
API 1:
- android:Theme 根主题
- android:Theme.Black 背景黑色
- android:Theme.Light 背景白色
- android:Theme.Wallpaper 以桌面墙纸为背景
- android:Theme.Translucent 透明背景
- android:Theme.Panel 平板风格
- android:Theme.Dialog 对话框风格
API 11:
- android:Theme.Holo Holo根主题
- android:Theme.Holo.Black Holo黑主题
- android:Theme.Holo.Light Holo白主题
API 14:
- Theme.DeviceDefault 设备默认根主题
- Theme.DeviceDefault.Black 设备默认黑主题
- Theme.DeviceDefault.Light 设备默认白主题
API 21: (网上常说的 Android Material Design 就是要用这种主题)
- Theme.Material Material根主题
- Theme.Material.Light Material白主题
兼容包v7中带的主题:
- Theme.AppCompat 兼容主题的根主题
- Theme.AppCompat.Black 兼容主题的黑色主题
- Theme.AppCompat.Light 兼容主题的白色主题
Material 的主题使用时需要注意:
- Material theme 只能在 21 以上运行
- Material theme 是在 android.Theme 下的
<style name="SplashTheme" parent="android:Theme.Material.Dialog">
style="@android:style/Theme.Material.Dialog"
主题风格如下:
- Black 黑色风格
- Light 光明风格
- Dark 黑暗风格
- DayNight 白昼风格
- Wallpaper 墙纸为背景
- Translucent 透明背景
- Panel 平板风格
- Dialog 对话框风格
- NoTitleBar 没有TitleBar
- NoActionBar 没有ActionBar
- Fullscreen 全屏风格
- MinWidth 对话框或者ActionBar的宽度根据内容变化,而不是充满全屏
- WhenLarge 对话框充满全屏
- TranslucentDecor 半透明风格
- NoDisplay 不显示,也就是隐藏了
- WithActionBar 在旧版主题上显示ActionBar
主题配置解析
主题里面很多配置参数的,大多数没法从字面意思猜是吗干的,要不很可能南辕北辙
颜色配置
- windowBackground
app默认的背景 - navigationBarColor
navigation bar页脚的背景色 - colorPrimaryDark
app 黑的基本色,主要用来做notification bar的背景. - colorPrimary
app 的基本颜色,将用作toolbar的背景色 - textColorPrimary
app 的文本颜色,用于toolbar的标题 - statusBarColor
状态栏颜色,21 以上有效
各种透明,数值都是 boolean 的
- windowIsTranslucent
主题背景透明
![](https://img.haomeiwen.com/i1785445/3e3a2e95d1bd6bbb.png)
网友评论