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 ...
随机推荐
- Aery的UE4 C++游戏开发之旅(3)蓝图
目录 蓝图 蓝图命名规范 蓝图优化 暴露C++至蓝图 暴露C++类 暴露C++属性 暴露C++函数 暴露C++结构体/枚举 暴露C++接口 蓝图和C++的结合方案 使用继承重写蓝图 使用组合重写蓝图 ...
- 【性能测评】DSP库,MDK5的AC5,AC6,IAR和Embedded Studio的三角函数性能
测试条件: 1.IAR8.30开最高等级速度优化. 2.MDK5.27正式版使用AC5开最高等级优化3,开启时间优化,测试C标准库和微库MicroLib两种. 3.MDK5.27正式版使用AC6开最高 ...
- 解决ES报错NoNodeAvailableException[None of the configured nodes are available:问题
elasticSearch的错误 NoNodeAvailableException[None of the configured nodes are available: [{#transport#- ...
- eclipse中js中文乱码问题的解决办法
在Eclipse中编辑JS文件简直是一种折磨,但是却总是很无奈得要去适应. 这里说一下Eclipse中,编辑JS文件时候,出现中文乱码问题的解决办法. 这个问题很容易想到是文件编码的问题,因此通常是修 ...
- RocketMq在SparkStreaming中的应用总结
其实Rocketmq的给第三方的插件已经全了,如果大家有兴趣的话请移步https://github.com/apache/rocketmq-externals.本文主要是结合笔者已有的rmq在spar ...
- Pick of the Week'19 | 图数据库 Nebula 第 47 周看点-- insert 的二三事
每周五 Nebula 为你播报每周看点,每周看点由本周大事件.用户问答.Nebula 产品动态和推荐阅读构成. 今天是 2019 年第 47 个工作周的周五,来和 Nebula 看看本周有什么图数据库 ...
- 一起学Spring之三种注入方式及集合类型注入
本文主要讲解Spring开发中三种不同的注入方式,以及集合数据类型的注入,仅供学习分享使用,如有不足之处,还请指正. 概述 Spring的注入方式一共有三种,如下所示: 通过set属性进行注入,即通过 ...
- WPF无边框可拖动窗体
下面主要记录下创建无边框窗体,并且可以拖动.这种窗体主要用于弹出小窗体时. <Window x:Class="WpfApplication1.MainWindow" xmln ...
- NLTK实现文本切分
之前已经了解了使用nltk库,将文本作为参数传入相应函数进行切分的方法,下面看看使用正则表达式如何来进行文本切分. 1. 使用正则表达式切分 1.1 通过RegexpTokenizer 进行切分.先导 ...
- django中使用原生的sql查询实例
在app文件夹下创建database_operations.py文件,写如下内容: import pymysql from 项目名.settings import DATABASES class Da ...