您当前的位置: 首页 >  android

Kevin-Dev

暂无认证

  • 0浏览

    0关注

    544博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

【Android -- Res资源】主题 Theme 的使用总结

Kevin-Dev 发布时间:2020-07-03 20:17:05 ,浏览量:0

前言

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 的父主题就各有不同了,你也可以从这个位置来自己修改主题,此文章主要就是来讨论这个主题如何修改。

Theme 主题的定义

在这里插入图片描述 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);
关注
打赏
1658837700
查看更多评论
立即登录/注册

微信扫码登录

0.0584s