前言
在 AndroidManifest.xml
文件中有 ,其中的 @style/AppTheme 是引用的 res/values/styles.xml 中的主题样式,也有可能是引用的
res/values-v11/styles.xml
或者 res/values-v14/styles.xml
,这是根据运行此程序的手机系统来决定的,如果手机系统的 API 版本是 11 以上就是 v11/styles.xml
,以此类推。在 values/styles.xml
中你会发现 AppTheme
的主题样式又是继承自 AppBaseTheme
,而 AppBaseTheme
的父主题就各有不同了,你也可以从这个位置来自己修改主题,此文章主要就是来讨论这个主题如何修改。
1. 在 AS 中
res/values/style.xml
中定义,例如新建项目 AS 自动创建的 Theme,是系统提供;
@color/colorPrimary
@color/colorPrimaryDark
@color/colorAccent
2. 常见的系统主题:
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="Translucent" 半透明
android:theme="Theme.Translucent.NoTitleBar" 半透明、无标题栏
android:theme="Theme.Translucent.NoTitleBar.Fullscreen" 半透明、无标题栏、全屏
android:theme=”Theme.Panel” 半透明,无标题,全屏
android:theme=”Theme.Light.Panel”平板风格显示
Theme 主题的使用
在 AndroidManifest.xml
为应用或者 Activity 设置 Theme,通过 android:theme = "@style/theme
主题名"来引入自己的主题:
//自定义的Theme
在 Java 代码中设置 Theme,**注意:**在 Activity 的 onCreate
方法中的 setContentView(R.layout.activity_main)
之前设置;
setTheme(R.style.AppTheme);