1style样式的目的:把相同的样式抽取出来 便于统一修改

<style name="text_content_style">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:text">我是文本</item>
        <item name="android:textColor">#ff0000</item>
        <item name="android:textSize">22sp</item>
  </style>

style节点的name自定义 要见名知意

item name和值 和 普通布局文件的键+值对应

2样式的继承:

示例

<style name="text_content_style_dark" parent="@style/text_content_style">
        <item name="android:textColor">#88ff0000</item>
  </style>

3继承上面的样式 并重写textColor

样式的优先级:样式的优先级比较低 控件调用样式后如果在控件内继续设置属性 属性会覆盖原来样式的属性

可以用属性值覆盖原来的样式

4样式的调用

布局文件中

<TextView style="@style/text_content_style" />
<TextView style="@style/text_content_style_dark" />

5demo

a定义样式:res/values/style

<resources><!--Base application theme, dependent on API level. This theme is replacedby AppBaseTheme from res/values-vXX/styles.xml on newer devices.--><style name="AppBaseTheme" parent="android:Theme.Light"><!--Theme customizations available in newer API levels can go inres/values-vXX/styles.xml, while customizations related tobackward-compatibility can go here.--></style><!-- Application theme. --><style name="AppTheme" parent="AppBaseTheme"><!-- All customizations that are NOT specific to a particular API-level can go here. --></style><style name="text_content_style"><item name="android:layout_width">wrap_content</item><item name="android:layout_height">wrap_content</item><item name="android:text">我是文本</item><item name="android:textColor">#ff0000</item><item name="android:textSize">22sp</item></style><style name="text_content_style_dark" parent="@style/text_content_style"><item name="android:textColor">#88ff0000</item></style></resources>

b.调用样式

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"tools:context=".MainActivity" ><TextView style="@style/text_content_style" /><TextView style="@style/text_content_style_dark" /><TextViewstyle="@style/text_content_style_dark"android:textColor="#000000" /></LinearLayout>

Android笔记 style样式相关推荐

  1. android学习笔记---50_样式与主题,给控件使用样式,给应用使用主题

    50_样式与主题 android学习笔记---50_样式与主题,给控件使用样式,给应用使用主题 2013/5/12 50_样式与主题 ----------------- android样式和主题(st ...

  2. android style(样式)和theme(主题)设置

    android应用程序如何设置样式,包括样式定义.单个view设置样式. 全局样式设置.样式继承关系. 1.样式定义 android的样式定义在res/values/style.xml文件中,类似we ...

  3. Android中Theme主题和Style样式使用介绍总结

    1.Theme主题 1.1.Theme主题作用范围 Theme主要是针对应用级别的或者说窗体级别,可以设置应用主题(应用换肤效果)和Activity的主题:主题是不能应用在某一个单独的View中:或者 ...

  4. Android笔记之Android基本控件布局与Activity的生命周期

    前言 喜欢安卓里千奇百怪的app,酷炫的UI或者好玩的游戏.想知道那些软件是如何做的,为什么我在微博里发一条消息,就能一直存在网上,让别人看到?为什么我点击一个按钮就出现了一个效果,某个功能?为什么滑 ...

  5. android 自定义主题样式

    From: http://blog.csdn.net/dawanganban/article/details/17732701 http://www.cnblogs.com/bluestorm/arc ...

  6. Android笔记一.深入理解Intent和IntentFilters(一)

    深入理解Intent和IntentFiler(一) 转载请表明出处:http://blog.csdn.net/u012637501(嵌入式_小J的天空)     为了比較深刻的理解并灵活使用Inten ...

  7. Android 笔记之 R 文件

    Android笔记之R文件 阅读目录 介绍 R 文件的内容 介绍 通过 R 文件引用资源 一.R 文件的内容 在 Android Studio 中 R 文件位于 app -> build -&g ...

  8. Android笔记 theme主题

    Android中theme与style的定义没有区别 区别在于控制范围 theme范围更大 style用于控制view对象 theme用于控制Activity样式 1在res/values下定义the ...

  9. Android中style和theme的区别

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

最新文章

  1. About Instruments
  2. openresty开发系列28--openresty中操作mysql
  3. malloc,calloc和realloc函数
  4. python除法函数一般如何命名_关于python:当用于除法时,’/’和’//’之间有什么区别?...
  5. VS2010中的sln,suo分别是什么文件
  6. 程序员山洞开发程序,两年敲45万行代码,网友:一般人扛不住
  7. Application Request Route实现IIS Server Farms集群负载详解
  8. vs2012新建项目时出现错误提示框解决办法
  9. 一次数据库的简单性能优化
  10. Cloudera迁移scm数据库
  11. 利用计算机技术分析学生成绩,基于数据挖掘技术的学生成绩分析
  12. 论文阅读:CVPR2021 | Involution: Inverting the Inherence of Convolution for Visual Recognition
  13. jav使用python模型实现方案
  14. C++ Redis mset 二进制数据接口封装方案
  15. 名单出炉!下一轮“双一流”,重点建设这些高校!
  16. 安卓圆形头像制作两种方法。
  17. 2022英语词汇积累
  18. IOS图像2之jpg、png图片保存、互转、设置有损压缩因子
  19. MeteoInfoLab脚本示例:站点填图
  20. VSCode使用chrom调试

热门文章

  1. python乘积函数_龙贝格求积公式(Python实现)
  2. html 最小长度单位,html见长度单位尺寸单�?CSS布局HTML
  3. 以后可得记住了--Python笔试面试题小结
  4. 33、JSONP跨域
  5. C语言之原码、反码和补码
  6. Bundler和Minifier Visual Studio扩展
  7. 关于eclipase出现的problems during content assist报错问题
  8. Asp.net MVC4 与 Web Form 并存
  9. 宏定义 是否retina高清屏,判断当前设备
  10. 怎么测试服务器端口是否对外开放_12个经典性能测试人员面试题