android_基础_常见主题theme风格详解

article/2025/8/22 5:20:47

本文出自门心叼龙的博客,转载请注明出处: https://blog.csdn.net/geduo_83/article/details/86560896

目录

1. 什么是Style,什么是Theme?

2. 在定义Theme的时候@符号和?符号有何区别?

3. 怎么通过代码给一个Activity设置主题?

4. AppTheme主题颜色colorPrimary,colorPrimaryDark,colorAccent都是什么的颜色?

​​5.常见的主题风格都有哪些?

6.ThemeOverlay使用特点?

7. 自定义样式属性

8. 自定义一个tootbar的样式?


1. 什么是Style,什么是Theme?

  • 1.1 联系

Style 和 theme:是一个包含一种 或者 多种格式化 属性 的集合 ,并且 style和theme都是资源,存放在res/values 文件夹下

  • 1.2 区别:

style:View级别的,只能在某个Activity的布局文件中使用
Theme:应用级别的,你必须在AndroidManifest.xml中 的或者中使用

2. 在定义Theme的时候@符号和?符号有何区别?

@符号 表明 我们引用的资源是前边定义过的(或者在前一个项目中或者在Android 框架中)。问号?表明 我们引用的资源的值在 当前的 主题当中定义过

3. 怎么通过代码给一个Activity设置主题?

protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState); setTheme(android.R.style.Theme_Light); setContentView(R.layout.linear_layout_3); 
}

4. AppTheme主题颜色colorPrimary,colorPrimaryDark,colorAccent都是什么的颜色?

  • 4.1 colorPrimary

App Bar 的背景色,即 ActionBar,通常也是一个 App 的主题色调。不过 ActionBar 已经退出历史舞台,由 Toolbar 代替使用,但是 Toolbar 需要在 layout 文件中单独使用 background 属性设置背景色,如:

<android.support.v7.widget.Toolbarandroid:layout_width="match_parent"android:layout_height="wrap_content"android:background="?attr/colorPrimary" />
  • 4.2 colorPrimaryDark

status bar(状态栏)背景色。仅作用于 Lollipop 及更高版本。

  • 4.3 colorAccent

许多控件在选中状态或获取焦点状态下使用这个颜色,常见有:

  • CheckBox:checked 状态

  • RadioButton:checked 状态

  • SwitchCompat:checked 状态

  • EditText:获取焦点时的 underline 和 cursor 颜色

  • TextInputLayout:悬浮 label 字体颜色

    等等
    
  • 4.4 android:navigationBarColor

navigation bar 背景色。仅作用于 Lollipop 及更高版本。

  • 4.5 colorControlNormal

某些 Views “normal” 状态下的颜色,常见如:unselected CheckBox 和 RadioButton,失去焦点时的 EditText,Toolbar 溢出按钮颜色,等等。

  • 4.6 colorControlActivated

某种程度上,是 colorAccent 的替代者,比如对于 CheckBox 和 RadioButton 的 checked 状态,colorControlActivated 属性会覆盖 colorAccent 属性的对应颜色。

  • 4.7 colorControlHighlight

所有可点击 Views 触摸状态下的 Ripple(涟漪)效果。仅作用于 Lollipop 及更高版本。

  • 4.8 colorButtonNormal

Button normal 状态下的背景色。注意,这种设置与 Button 的 android:background 属性改变背景色不同的是,前者在 Lollipop 及更高版本上会让 Button 依旧保持阴影和 Ripple 触摸效果。

  • 4.9 android:windowBackground

窗口背景色,诸如此类的还有:android:background,android:colorBackground 等。

  • 4.10 android:textColorPrimary

EditText 的 text color,等等文本颜色。

  • 4.11 navigationIcon

返回按钮的图片

在这里插入图片描述

在这里插入图片描述

5.常见的主题风格都有哪些?

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”

在这里插入图片描述

6.ThemeOverlay使用特点?

当在某个Activity有些特殊要求的时候就可以用ThemeOverlay继承全局的样式,来修改自己的个性化样式,注意了该样式的引用只能设置在布局文件上,不能在清单文件里面进行设置
定义:

<style name="AppTheme.Secondary" parent="ThemeOverlay.AppCompat"><item name="colorAccent">@color/colorPrimary</item>
</style>

调用:

<FrameLayoutandroid:background=”@color/dark_background”android:theme="@style/ThemeOverlay.AppCompat.Dark”><TextView />
</FrameLayout>

单独给toolbar设置样式

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="?android:attr/actionBarSize"android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"android:background="?attr/colorPrimary">
</android.support.v7.widget.Toolbar>

7. 自定义样式属性

  • 7.1 首先在attrs.xml 定义属性名称
<?xml version="1.0" encoding="utf-8"?>
<resources><declare-styleable name="AppTheme.NoActionBar"><attr name="baseTitleTextColor" format="reference|color" /><attr name="titleDividerColor" format="reference|color" /><attr name="titleDividerLine" format="dimension" /> </declare-styleable>
</resources>
  • 7.2 在style.xml中使用自定义的属性
<style name="AppTheme.NoActionBar"><item name="windowActionBar">false</item><item name="windowNoTitle">true</item><item name="baseTitleTextColor">#2a2a2a</item><item name="titleDividerLine">1dp</item><item name="titleDividerColor">@android:color/transparent</item>
</style>
  • 7.3 在布局文件中引用样式
 <Viewandroid:id="@+id/view_divider"android:layout_width="match_parent"android:layout_height="?attr/titleDividerLine"android:background="?attr/titleDividerColor"/>

8. 自定义一个tootbar的样式?

  • 8.1 定义一个NoActionBar的样式
<style name="TestAppTheme" parent="Theme.AppCompat.Light"><item name="windowActionBar">false</item><item name="windowNoTitle">true</item><item name="colorPrimary">#6a1b9a</item><item name="colorPrimaryDark">#ec407a</item><item name="colorAccent">#f44336</item></style>
  • 8.2 布局中引人Toolbar
<android.support.v7.widget.Toolbar   
xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:background="#4e342e"android:layout_height="wrap_content"android:minHeight="?attr/actionBarSize">
</android.support.v7.widget.Toolbar  >
  • 8.3 在Activity中设置Toobar为ActionBar
public class TestAppComActivity extends AppCompatActivity{@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_testappcompat);Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);setSupportActionBar(toolbar);}
}

http://chatgpt.dhexx.cn/article/14kFgkLJ.shtml

相关文章

iview 实现在theme主题中添加某一个新模块的主题颜色切换

背景&#xff1a;直接下载的iview-admin 1.3.1模板 1、iview 自带主题theme 主要有4个颜色组成 分别为 默认的蓝色&#xff0c;其他分别为红色&#xff0c;蓝色&#xff0c;洋红色&#xff1b;然后在根据菜单栏是否为黑色和白色的组合状态所以有8中组合的主题&#xff1b; 2、…

Android——Theme和Style-由浅入深,全面讲解

1、官方详细解读 样式和主题背景 | Android 开发者 | Android Developers 2、应用场景 类似web设计中css样式。将应用设计的细节与界面的结构和行为分开。 样式style &#xff1a;应用于 单个 View 的外观。样式可以指定字体颜色、字号、背景颜色等属性 主题theme&…

关于eclipse IDE安装Darkest Dark Theme主题插件

听说Darkest Dark Theme是现在最受欢迎的eclipse主题插件&#xff0c;于是我也来搞了一下。 Darkest Dark Theme官方网站(打开慢的要死&#xff0c;不知道是不是只有我会有这个问题。) https://marketplace.eclipse.org/content/darkest-dark-theme安装教程&#xff1a; 1.打开…

Vue Theme主题样式整理

为什么80%的码农都做不了架构师&#xff1f;>>> 一、ElementUI官方主题在线生成预览 https://elementui.github.io/theme-chalk-preview/#/zh-CN 使用步骤&#xff1a; 1.选择主题颜色&#xff0c;下载主题 包&#xff0c;然后解压 2.找到node_modules下的element-u…

Android Theme 常见主题风格详解

本文为自己多年来在Android实战开发过程中总结归纳的一些常见问题&#xff0c;现在分享出来希望对初学者有所帮助。 本文出自门心叼龙的博客&#xff0c;转载请注明出处&#xff1a; https://blog.csdn.net/geduo_83/article/details/86560896 目录 1. 什么是Style&…

Android自带的Theme主题图解

一、Manifest文件中: 从上图中我们可以看到在这个应用程序中我们的主题应用的是 AppTheme ,然后我们去看看 AppTheme 。 二、style.xml文件中: 这个文件是在应用工程中的: 然后又可以发现 AppTheme 主题样式是继承自 AppBaseTheme 主题样式的, 而 AppBaseTheme 主题样式又…

OpenWRT LUCI Theme主题定制

本人所写的博客都为开发之中遇到问题记录的随笔,主要是给自己积累些问题。免日后无印象,如有不当之处敬请指正(欢迎进扣群 24849632 探讨问题); 我们在github上先找一个合适的主题 https://github.com/search?q=luci+theme 比如我们以 rosywrt/luci-theme-rosy 为例 第…

Android的Theme主题切换

简单的Theme换肤功能 效果截图 1、定义属性 先定义几个需要改变的属性&#xff0c;例如&#xff1a; <!--换肤--><attr name"userNameColor" format"color" /><attr name"commonColor" format"color" /><…

Eclipse设置Theme主题颜色

设置Eclipse的代码编辑区背景为暗黑色系&#xff1a; 如需转载&#xff0c;请注明转载自&#xff1a;blog.csdn.net/it1988888 相关文件下载&#xff1a;http://guari.github.io/eclipse-ui-theme/ 方案一--下载颜色主题配置文件&#xff0c;离线导入配色方案的设置&#xf…

Jupyter lab Theme 主题更换

Jupyter lab Theme 主题更换 1. 打开Jupyter-lab2. 再拓展插件中搜索 “theme”3. 安装自己喜欢的主题4. 在Setting->JupyterLab Theme->选择"自己刚安装的主题"jupyterlab_miami_nights 主题jupyterlab_onedarkpro 主题 1. 打开Jupyter-lab 2. 再拓展插件中搜…

PySimpleGui theme主题使用

第一章 PySimpleGui theme主题使用 目录 系列文章目录 前言 一、theme是什么&#xff1f; 二、使用步骤 1.打印所有主题&#xff1a; 2.主题设置 3.更新主题的设置 总结 前言 通过设置主题&#xff0c;可快速设置GUI的颜色&#xff0c;节省自己设置UI的时间 一、theme是什么&a…

Hexo修改theme主题

学习目标 本文主要学习的内容如下&#xff1a; 如何去获取到 NexT 主题 如何去安装和配置 NexT 主题 设置菜单&#xff0c;如分类&#xff0c;标签&#xff0c;关于我等简单配置 获取开源的 Hexo 主题 在上节介绍如何快速去搭建 Hexo &#xff0c;最终展示的效果如下图所…

【Android开发基础】应用界面主题Theme使用方法

主题Theme就是用来设置界面UI风格&#xff0c;可以设置整个应用或者某个活动Activity的界面风格。在Android SDK中内置了下面的Theme&#xff0c;可以按标题栏Title Bar和状态栏Status Bar是否可见来分类&#xff1a; •android:theme"android:style/Theme.Dialog" …

Flutter 基础之 Theme 主题(样式篇)

声明&#xff1a;本篇文章已授权微信公众号 YYGeeker 独家发布。 博主原创文章&#xff0c;转载请注明出处&#xff1a;小嵩的博客 一、介绍 Theme 类将主题应用于子控件&#xff0c;Theme&#xff08;主题&#xff09;它描述了应用程序的颜色和排版选择。Theme有两种&#x…

Android中Theme主题和Style样式使用介绍总结

1.Theme主题 1.1.Theme主题作用范围 Theme主要是针对应用级别的或者说窗体级别&#xff0c;可以设置应用主题&#xff08;应用换肤效果&#xff09;和Activity的主题&#xff1b;主题是不能应用在某一个单独的View中&#xff1b;或者说Theme是用来设置应用全局主题风格的&…

【转】提升工作效率的一些小技巧——资源管理器篇

当我看到有人打开资源管理器&#xff0c;一个一个文件夹点进去&#xff0c;再点出来&#xff0c;我就着急。特别是有人在会议上打开我的电脑&#xff0c;然后寻找文件&#xff0c;我就特别捉急&#xff0c;这不只是在浪费自己的时间&#xff0c;还浪费参加会议人的时间。 我把资…

WPF 4 开发Windows 7 任务栏(Overlay Icon、Thumbnail Toolbar、Progress Bar)

在上一篇我们介绍了如何在WPF 4 中开发Windows 7 跳转列表&#xff0c;本篇将继续针对WPF 4 中任务栏其他功能&#xff1a;覆盖图标&#xff08;Overlay Icon&#xff09;、进度条&#xff08;Progress Bar&#xff09;、缩略图工具栏&#xff08;Thumbnail Toolbar&#xff09…

HTML+CSS提升小实战

1 <html>2 <head>3 <meta http-equiv"Content-Type" content"text/html; charsetutf-8" />4 <title>几米简介</title>5 <style type"text/css">6 *{7 margin:0px;padding:0px;8 …

java实现qlearning,DQN(Deep Q-learning)入门教程(一)之强化学习介绍

什么是强化学习? 强化学习(Reinforcement learning,简称RL)是和监督学习,非监督学习并列的第三种机器学习方法,如下图示: 首先让我们举一个小时候的例子: 你现在在家,有两个动作选择:打游戏和读书。如果选择打游戏的话,你就跑到了网吧,选择读书的话,就坐在了书桌面前…

实验一 书桌

实验内容&#xff1a; 了解四种视图&#xff0c;在绘制时&#xff0c;从不同的视图进行观察&#xff0c;提高绘制效率。知道常用工具的快捷键 一、四种视图 1、顶视图&#xff08;T&#xff09; 2、前视图&#xff08;F&#xff09; 3、左视图&#xff08;L&#xff09; 4、透…