Android 中的style和Theme的使用
说明
style和theme的定义是为了改变原有系统设定的默认窗体、字体、背景色、格式等风格而使用。其本质就是系统属性的集合。本篇主要介绍android中的style和theme的具体用法。
style和Theme
style和theme均是对于系统的莫些属性的值的修改,应用(reference)类型均为style类型,不同的是style是用来设置单个view(控件)的,而theme则是用于应用与某个节目的整体风格的。使用场景分别为界面属性设置和activity或application theme应用。如下:
//style使用,注意style不需要添加"android"
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.haolianluo.myapplication.MainActivity">
<TextView
style="@style/CustomerTextStyle" />
</android.support.constraint.ConstraintLayout>
//theme使用
......
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:theme="@style/Animation.AppCompat.Dialog">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
//style格式设置
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="CustomerTextStyle">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:gravity">center</item>
<item name="android:text">Customer Text</item>
<item name="android:textColor">@android:color/holo_blue_bright</item>
<item name="android:textSize">18sp</item>
</style>
</resources>
单个设置style或许感觉麻烦,但对于整体风格保持一致的某些特定控件的属性统一设置却很适用,可以减少很多不必要的代码,且便于统一修改界面风格。theme则常见于修改界面的titlebar、actionbar、dialog风格等系统UI格式风格,但由于定制的非完全开放原因,并不能保证可以完全满足你的要求,对于一些轻量级的修改可供适用,适用其的最直接原因是,可以全局统一,保持整体风格统一。如下,是我在官网找的style和theme所用属性的源码,可供参考:
Android 中的style和Theme的使用的更多相关文章
- 【转】说说Android中的style和theme
最近在做软件从2.3到4.0的改变的一些工作,其中涉及了一些style和theme相关的东西.上网上查了一些东西,这个一并说说.关于android中style和theme的基本使用,这里就不再赘述了, ...
- Android中的 style 和 theme
通过设置 view 控件的属性,达到设置android UI的目的,如果某些 属性值复用率很高,可以考虑将属性单独声明在 style中,这样就可以达到复用的效果. 一.style Style 概念:A ...
- 【转】android中的Style与Theme
Android默认情况下提供了一些实用的主题样式,比如说Theme.Dialog可以让你的Activity变成一个窗口风格,而Theme.Light则让你的整个Activity具有白色的背景,而不是黑 ...
- android中的style部分属性值介绍
转自:http://blog.sina.com.cn/s/blog_70c759fd01013phv.html Android平台定义的主题样式: android:theme="@andro ...
- android中的style部分属性值介绍 --zz
Android平台定义的主题样式: android:theme="@android:style/Theme.Dialog" 将一个Activity显示为对话框模式 •andro ...
- ArcGIS Runtime SDK for Android中SimpleFillSymbol.Style样式
SimpleFillSymbol.Style样式枚举共8种: 1.BACKWARD_DIAGONAL 反对角线填充 2.CROSS 交叉线填充 3.DIAGONAL_CROSS 前后对角线填充 4.F ...
- Android中Style和Theme的使用
Style: Style是View中一些属性的集合,包括height,padding,font color,background等等,Style单独定义在xml文件中,类似与web页面中css的角色, ...
- Android中theme.xml与style.xml的区别
一.相同点 两者的定义相同.继承方式也相同 <?xml version="1.0" encoding="utf-8"?> <resources ...
- Android中style和theme的区别
在学习Xamarin android的过程中,最先开始学习的还是熟练掌握android的六大布局-LinearLayout .RelativeLayout.TableLayout.FrameLayou ...
随机推荐
- github pages 子域名 ( subdomain ) https 认证
目录 说明 github pages 上的创建子域名 https 认证 说明 转载请注明出处https://www.cnblogs.com/bllovetx/p/12013462.html 欢迎访问我 ...
- 搭建API Mock
所需环境 Node.js + MySQL 5.7+ Redis 4.0+ Node.js 安装 .要安装nvm,需要安装构建源包所需的工具,CentOS 上安装,用这些命令来安装构建工具: sudo ...
- PHP最新面试题2019
1.字符串"0"在PHP和js中转换为布尔值是false还是true php:false; php 弱语言 '0'和0一样: js:true:字符串除了空字符串('')其他都是t ...
- unity3D开发环境搭建
前言 本文记录unity3D开发环境的搭建 unity安装 unity有中文官网(https://unity.cn/),很贴心,ide工具我们选择下载安装中国区增强版,下载地址:https://uni ...
- 学习 C#,从 Hello world 开始吧
目录 Hello world 创建.编辑.编译和运行 C# 源代码 使用 .NET Core 命令行接口 (CLI) 工具 使用 Visual Studio 创建项目 编译和执行 总结 C#(读作 & ...
- .NET面试题解析(9)-SQL语言基础及数据库基本原理
见面试题 1. 索引的作用?她的优点缺点是什么? 2. 介绍存储过程基本概念和 她的优缺点? 3. 使用索引有哪些需要注意的地方? 4. 索引碎片是如何产生的?有什么危害?又该如何处理? 5. 锁的目 ...
- ling to sql创建临时变量 let的使用
使用let赋值给临时变量 var dailys = from f in _postgreDbContext.draws let temp = f.review_time.Value.Date wher ...
- C lang: VLA(variable-length array)
Xx_VLA Introduction VLA:variable-length array,not variable array size,but variable arary dimensional ...
- canvas在vue中的应用
使用cavas可以绘制各种图表.生成二维码.制作H5小游戏. 生命周期 canvas应该在mounted的生命周期中初始化,在updated中是无效的. export default { mounte ...
- hadoop搭建的前期准备
这个hadoop的搭建是以比赛前的练习为目的的,所以我直接以root用户来搭建hadoop,主要也是方便我自己以后复习用的 需要的软件:vmware15.5,xshell6,xftp6,jdk Lin ...