说明

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所用属性的源码,可供参考:

Enjoytoday,EnjoyCoding

Android 中的style和Theme的使用的更多相关文章

  1. 【转】说说Android中的style和theme

    最近在做软件从2.3到4.0的改变的一些工作,其中涉及了一些style和theme相关的东西.上网上查了一些东西,这个一并说说.关于android中style和theme的基本使用,这里就不再赘述了, ...

  2. Android中的 style 和 theme

    通过设置 view 控件的属性,达到设置android UI的目的,如果某些 属性值复用率很高,可以考虑将属性单独声明在 style中,这样就可以达到复用的效果. 一.style Style 概念:A ...

  3. 【转】android中的Style与Theme

    Android默认情况下提供了一些实用的主题样式,比如说Theme.Dialog可以让你的Activity变成一个窗口风格,而Theme.Light则让你的整个Activity具有白色的背景,而不是黑 ...

  4. android中的style部分属性值介绍

    转自:http://blog.sina.com.cn/s/blog_70c759fd01013phv.html Android平台定义的主题样式: android:theme="@andro ...

  5. android中的style部分属性值介绍 --zz

    Android平台定义的主题样式: android:theme="@android:style/Theme.Dialog"   将一个Activity显示为对话框模式 •andro ...

  6. ArcGIS Runtime SDK for Android中SimpleFillSymbol.Style样式

    SimpleFillSymbol.Style样式枚举共8种: 1.BACKWARD_DIAGONAL 反对角线填充 2.CROSS 交叉线填充 3.DIAGONAL_CROSS 前后对角线填充 4.F ...

  7. Android中Style和Theme的使用

    Style: Style是View中一些属性的集合,包括height,padding,font color,background等等,Style单独定义在xml文件中,类似与web页面中css的角色, ...

  8. Android中theme.xml与style.xml的区别

    一.相同点 两者的定义相同.继承方式也相同 <?xml version="1.0" encoding="utf-8"?> <resources ...

  9. Android中style和theme的区别

    在学习Xamarin android的过程中,最先开始学习的还是熟练掌握android的六大布局-LinearLayout .RelativeLayout.TableLayout.FrameLayou ...

随机推荐

  1. Cesium 本地部署案例

    众所周知,cesium的服务器是搭建在国外的,所以我们国内的用户访问的时候贼慢.有时想查个api或者看个案例半天都进不去,今天我来说一下傻瓜式搭建本地的cesium环境,用于大家没事查资料用!步骤:1 ...

  2. inux 网络监控分析

    一.sar -n:查看网卡流量 -n 参数,他有6个不同的开关:DEV | EDEV | NFS | NFSD | SOCK | ALL .DEV显示网络接口信息,EDEV显示关于网络错误的统计数据, ...

  3. 14集超详细视频教程,手把手教你用数据神器Hawk!

    沙漠君在闭关4个月后,终于把开源数据神器Hawk(详细介绍在这里)的文档和教学视频基本录制完毕, 并同步更新在有爱无广告二次元的B站! 教程总时间超过3个小时,覆盖了网页采集器,数据清洗,文件读写等方 ...

  4. Serverless 实战——使用 Rendertron 搭建 Headless Chrome 渲染解决方案

    为什么需要 Rendertron? 传统的 Web 页面,通常是服务端渲染的,而随着 SPA(Single-Page Application) 尤其是 React.Vue.Angular 为代表的前端 ...

  5. jQuery实现下拉框默认选中

    <form class="form-inline" method="post" action="/score_result/"> ...

  6. 松软科技web课堂:随机Math.random()

    Math.random() 返回 0(包括) 至 1(不包括) 之间的随机数: 实例 Math.random(); // 返回随机数 JavaScript 随机整数 Math.random() 与 M ...

  7. vue常见问题处理 -- 页面刷新时,如何保持原有vuex中的state信息

    一.页面刷新时,如何保持原有vuex中的state信息 页面刷新后,原有的 vuex 中的 state 会发生改变,如果在页面刷新之前,可以将 state 信息保存,页面重新加载时,再将该值赋给 st ...

  8. MySQL5.6与MySQL5.7安装的区别

    一.MySQL5.6与MySQL5.7安装的区别 1.cmake的时候加入了boost 下载boost.org 2.初始化时 cd /application/mysql/bin/mysql 使用mys ...

  9. centos7设置静态ip-修改配置文件方式

    修改IP地址为静态地址需要修改配置文件,首先打开配置文件,在控制台输入cd /etc/sysconfig/network-scripts 输入ifconfig,这样就可以看到你的ip地址等信息了. v ...

  10. diango中有三种response

    from django.shortcuts import render, redirect, HttpResponse HttpResponse() render() redirect()