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 ...
随机推荐
- 痛苦的 java.net.BindException: Address already in use: connect —— Nacos的坑
我的dubbo应用, 刚开始的时候,启动一两个是没有问题的, 启动多了就大量出现: -- :: --- [TaskScheduler-] o.s.c.a.nacos.discovery.NacosWa ...
- 我这样回答了Spring 5的新特性,面试官对我刮目相看
最近,有一个小伙伴拿到了自己满意的Offer,和他交谈的过程中得知他面试官问他关于Spring的问题比较多,其中最让面试官满意的就是自己回答关于Spring 5的知识点回答的不错. Spring5于2 ...
- Linux之shell详解
Shell是什么 Shell 是一个用 C 语言编写的程序,它是用户使用 Linux 的桥梁.Shell 既是一种命令语言,又是一种程序设计语言.Shell 是指一种应用程序,这个应用程序提供了一个界 ...
- Hyperledger Fabric私有数据
官方文档:点这里 1简介 在同一个通道中,允许某一组织在对同一通道内其他组织保持部分的数据私有.也就是说有一部分被标识为私有的数据只能具有权限的组织查看和操作,而其余组织不具备查看和操作私有数据的权限 ...
- Mysql - 高可用方案之MMM(一)
一.概述 本文将介绍mysql的MMM(Master-Master replication manager for MySQL)方案.官方文档地址:https://mysql-mmm.org/star ...
- Java 基础复习 -- Enum 类
一.枚举类基本语法 在 Java SE5 中添加了一个看似很小的特性,即 enum 关键字,它使得我们在需要群组并使用枚举类型集时,可以很方便的处理. 所有的 enum 都继承自 java.lang. ...
- 剑指offer笔记面试题5----替换空格
题目:请实现一个函数,把字符串中的每个空格替换成"20%".例如,输入"We are happy."则输出"We%20are%20happy.&quo ...
- CODING 2.0:为什么我们需要 DevOps
CODING 在前两天的 Kubecon 2019 大会上发布了 CODING 2.0.这背后是 CODING 对研发管理和研发团队组建的思考.从 CODING 成立以来,我们一直在探索"让 ...
- 开启docker
systemctl daemon-reload systemctl restart docker.service
- 初学Elasticsearch
首先启动elasticsearch.bat,然后安装node.js为了支持elasticsearch-head-master插件,之后在在该插件的目录打开命令行窗口,输入grunt server即可S ...