1.theme和style都是一组属性的集合,用于定义文本、颜色、大小等显示风格。他们都是资源,可以用android系统级别的一些默认的风格和主题资源,你也可以自定义你自己的主题和风格资源。

2.自定义style

 <resources>
<style name="CustomTheme">
<item name="android:windowNoTitle">true</item>
<item name="windowFrame">@drawable/screen_frame</item>
<item name="windowBackground">@drawable/screen_background_white</item>
<item name="panelForegroundColor">#FF000000</item>
<item name="panelBackgroundColor">#FFFFFFFF</item>
<item name="panelTextColor">?panelForegroundColor</item>
<item name="panelTextSize">14</item>
<item name="menuItemTextColor">?panelTextColor</item>
<item name="menuItemTextSize">?panelTextSize</item>
</style>
</resources>

注意:@符号表明了我们应用的资源是前边定义过的(或者在前一个项目中或者在Android 框架中)。?符号表明了我们引用的资源的值在当前的主题当中定义过。通过引用在<item>里边定义的名字可以找到(panelTextColor 用的颜色和panelForegroundColor中定义的一样)。这中技巧只能用在XML资源当中。

3.自定义Style(2)

    <style name="AppBaseTheme" parent="android:Theme"></style>

    <style name="AppTheme" parent="AppBaseTheme">
<item name="android:textSize">50sp</item>
</style> <style name="AppTheme.Test" parent="android:Theme.Light">
<item name="android:textColor">#ff0000</item>
</style> <style name="AppTheme.Test.Blue">
<item name="android:textColor">#0000ff</item>
</style> <style name="AppTheme.Test.Blue.New">
<item name="android:textColor">#0000ff</item>
<item name="android:textSize">30sp</item>
</style>

  parent字段标明改style从哪种style继承过来,然后我们就可以在该style 内复写父style中的一些风格,比如字体、颜色etc。

  以下有几点要注意一下:

    1.第三种style是通过A.B这样的形式定义的,这是继承的另外一种简易的写法。但只要有parent属性,那么parent会完全覆盖A的所有属性,即A写不写都是一样的,该自

     定义style 不会从A继承到任何风格,这里用上面的例子运行一下就可以看出来;

    2.如果自定义的style没有parent属性,那么style的name中的A部分可以不写,这表明这是我们自定义的style,但是如果用简易的写法来写,而且又不想写parent的话

那么A必须是声明过的,否则会报错“A主题找不到”;

    3.简易的写法支持多继承。

3.接下来我们就可以在manifest中,或者指定的空间直接使用我们自定义的style 了。

  

android 中theme和style的语法相关的更多相关文章

  1. android 中theme.xml与style.xml的区别

    from://http://liangoogle.iteye.com/blog/1848448 android 中theme.xml与style.xml的区别: 相同点: 两者的定义相同. <r ...

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

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

  3. android中SELINUX规则分析和语法简介【转】

    本文转载自:https://blog.csdn.net/LoongEmbedded/article/details/62430039 1. SELINUX是可以理解为一种Android上面的安全机制, ...

  4. android中SELINUX规则分析和语法简介

    1. SELINUX是可以理解为一种android上面的安全机制,是有美国国家安全局和一些公司设计的一个针对linux的安全加强系统我们可以通过配置SELINUX的相关policy,来定制自己的手机的 ...

  5. 正确使用 Android 的 Theme 和 Style

    原文:http://www.tuicool.com/articles/ZjEZFj Android 5.0 可以给一个 View 单独设置一个 theme 了,其主要用途就是用在 ToolBar 上, ...

  6. android 中theme样式的解释

    android:theme="@android:style/Theme.Dialog" : Activity显示为对话框模式 android:theme="@androi ...

  7. Android中Bitmap和Drawable,等相关内容

    一.相关概念 1.Drawable就是一个可画的对象,其可能是一张位图(BitmapDrawable),也可能是一个图形(ShapeDrawable),还有可能是一个图层(LayerDrawable) ...

  8. Android开发之Theme、Style探索及源码浅析

    1 背景 前段时间群里有伙伴问到了关于Android开发中Theme与Style的问题,当然,这类东西在网上随便一搜一大把模板,所以关于怎么用的问题我想这里也就不做太多的说明了,我们这里把重点放在理解 ...

  9. Android中解析JSON形式的数据

    1.JSON(JavaScript Object Notation) 定义: 一种轻量级的数据交换格式,具有良好的可读和便于快速编写的特性.业内主流技术为其提供了完整的解决方案(有点类似于正则表达式, ...

随机推荐

  1. HDU 1712 分组背包

    ACboy needs your help Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  2. nginx 目录文件列表功能配置

    工作中常常有写不能有网页下载东西的需求,在Apache下搭建完成后直接导入文件即可达到下载/显示文件的效果,而Nginx也可以满足这样的需求(nginx 目录列表功能默认是关闭的),这时就需要配置. ...

  3. HTML中强大的input标签属性

    用了许久的html,<input>这个标签是最常用的标签之一. <input type="">标签中type属性是必不可少的,以往我最常用的有 type=& ...

  4. OpenLDAP安装

    参考: http://54im.com/openldap/centos-6-yum-install-openldap-phpldapadmin-tls-%E5%8F%8C%E4%B8%BB%E9%85 ...

  5. http get/post解决乱码问题

    <form method="默认为get"-> <s:form mothod="默认为post"-> ================= ...

  6. Get the current user permission level on a list item with ecmascript 分类: Sharepoint 2015-07-14 14:13 7人阅读 评论(0) 收藏

    To Check current users permissions using Ecmascript\Javascript client object model SharePoint 2010. ...

  7. wx jssdk

    public static Dictionary<string,string> jsstr(string url) { //noncestr ); //timestamp TimeSpan ...

  8. Unity3D之C# yield waitforseconds

    Wait for seconds requires a couple things in order to work properly and chances are if it's not work ...

  9. OpenCV中的矩阵操作

    函数 Description 说明 cvAdd Elementwise addition of two arrays 两个数组对应元素的和 cvAddS Elementwise addition of ...

  10. 百度前端技术学院2015JavaScript基础部分实现自己的小型jQuery

    // 实现一个简单的Query function $(selector) { ); if (firstChar == "#") { var len = selector.split ...