android Style(样式)的解析
来源:互联网 发布:java变量怎么初始化 编辑:程序博客网 时间:2024/06/11 08:08
先说下为啥要使用样式吧,举个例子来说吧
当要做这样的一个布局的时候
每个标签都要写的话,会感觉怎样
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:orientation="horizontal" > <Button android:id="@+id/bt1" android:layout_width="match_parent" android:layout_height="35sp" android:layout_marginLeft="6dp" android:layout_marginRight="10dp" android:layout_weight="1" android:background="#009999" android:text="上班族" android:textColor="#ffffff" android:textSize="11sp" /> <Button android:id="@+id/bt2" android:layout_width="match_parent" android:layout_height="35sp" android:layout_marginRight="10dp" android:layout_weight="1" android:background="#009999" android:text="医疗" android:textColor="#ffffff" android:textSize="11sp" /> <Button android:id="@+id/bt3" android:layout_width="match_parent" android:layout_height="35sp" android:layout_marginRight="10dp" android:layout_weight="1" android:background="#009999" android:text="媒体" android:textColor="#ffffff" android:textSize="11sp" /> <Button android:id="@+id/bt4" android:layout_width="match_parent" android:layout_height="35sp" android:layout_marginRight="6dp" android:layout_weight="1" android:background="#009999" android:text="白领" android:textColor="#ffffff" android:textSize="11sp" /> </LinearLayout>
要写很多这样的,不停的重复写是不是很烦呢,为了方便我们要学习样式了,
样式资源
首先要明白样式资源是用来干啥的,
样式资源主要用于对组件的显示样式经行控制,改变文本框显示文字的大小和颜色
位置:
res/values 目录中,
它的根元素是<resources></resources>标记,
在该元素中,使用<style></style>标记定义样式,
做的时候到values下找到styles
我把上面的代码简化下
这个就是要在xml中写的提前用style写好这样在
xml中不用写了
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:orientation="horizontal" > <Button android:id="@+id/bt1" style="@style/button" android:layout_marginLeft="10dp" android:text="上班族" /> <Button android:id="@+id/bt2" style="@style/button" android:text="医疗" /> <Button android:id="@+id/bt3" style="@style/button" android:text="媒体" /> <Button android:id="@+id/bt4" style="@style/button" android:text="白领" /> </LinearLayout>它的效果图
这样是不是很方便了,样式的好处就是一次写好多出都能调用
下面的标签也是能调用的
1 0
- android Style(样式)的解析
- Android Style Resource --- style样式的定义
- Android系统的样式style
- android 样式style的设置
- Android Style样式的定义和应用
- android的样式(style)与主题(theme)
- android自定义样式style的用法
- android的样式(style)与主题(theme)
- android的样式(style)与主题(theme)
- android的样式(style)与主题(theme)
- android的样式(style)与主题(theme)
- android的样式(style)与主题(theme)
- android的样式(style)与主题(theme)
- android的样式(style)与主题(theme)
- android的样式(style)与主题(theme)
- android的样式(style)与主题(theme)
- android的样式(style)与主题(theme)
- android的样式(style)与主题(theme)
- C++ STL stack/queue
- Makefile 学习日记(五)——makefile中的函数
- 100万并发连接服务器笔记之Java Netty处理1M连接会怎么样
- uva10825 (暴力)
- Spark内核讲解之弹性分布数据集(一)
- android Style(样式)的解析
- PB中,在用grid形式的数据窗口中,跨列标题头的制作方法
- stmmac ethernet
- Spark内核介绍:Spark在运行时会把Stage包装成任务提交 (二)
- 代理模式
- LayoutInflater 填充器填充布局,布局属性失效问题
- 模式、关系范式与关系运算
- Linux下软链接与硬链接的区别
- JS - 获取元素的值