android中自定义attr,以及style杂谈
来源:互联网 发布:企业的域名 编辑:程序博客网 时间:2024/06/06 02:32
attr 属性
style 样式
二者都是在res/values下面的xml文件
attr: for example:
类似的"layout_height,layout_width"都是属性
style就是这个控件设定好的一些值,方便重复调用
自定义的一个样式"TextStyle"
使用的android默认的属性shadowDx..设置好的具体的值
自定义的attr: 这个format就是格式
reference 表示引用,参考某一资源ID
string 表示字符串
color 表示颜色值
dimension 表示尺寸值
boolean 表示布尔值
integer 表示整型值
float 表示浮点值
fraction 表示百分数
enum 表示枚举值
flag 表示位运算
使用的时候,在布局文件头里
添加
xmlns:myapp="http://schemas.android.com/apk/res/包名"
在xml文件里使用跟系统自带控件一样使用
类似下面的语法
myapp:vpiIconPageIndicatorStyle="xxxxx"
====================================================================================================================================================================
上边的如果要使用自定义的属性进行自定义样式
格式应该是
attr和style格式都是需要<resources>起头的
获取示例:
style 样式
二者都是在res/values下面的xml文件
attr: for example:
- <LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
类似的"layout_height,layout_width"都是属性
style就是这个控件设定好的一些值,方便重复调用
自定义的一个样式"TextStyle"
使用的android默认的属性shadowDx..设置好的具体的值
- <style name="TextStyle">
- <item name="android:shadowDx">-0.5</item>
- <item name="android:shadowDy">1</item>
- <item name="android:shadowRadius">0.5</item>
- <item name="android:singleLine">true</item>
- <item name="android:ellipsize">marquee</item>
- </style>
自定义的attr: 这个format就是格式
reference 表示引用,参考某一资源ID
string 表示字符串
color 表示颜色值
dimension 表示尺寸值
boolean 表示布尔值
integer 表示整型值
float 表示浮点值
fraction 表示百分数
enum 表示枚举值
flag 表示位运算
- <resources>
- <declare-styleable name="ViewPagerIndicator">
- <!-- Style of the circle indicator. -->
- <attr name="vpiCirclePageIndicatorStyle" format="reference"/>
- <!-- Style of the icon indicator's views. -->
- <attr name="vpiIconPageIndicatorStyle" format="reference"/>
- <!-- Style of the line indicator. -->
- <attr name="vpiLinePageIndicatorStyle" format="reference"/>
- <!-- Style of the title indicator. -->
- <attr name="vpiTitlePageIndicatorStyle" format="reference"/>
- <!-- Style of the tab indicator's tabs. -->
- <attr name="vpiTabPageIndicatorStyle" format="reference"/>
- <!-- Style of the underline indicator. -->
- <attr name="vpiUnderlinePageIndicatorStyle" format="reference"/>
- </declare-styleable>
- </resources>
使用的时候,在布局文件头里
添加
xmlns:myapp="http://schemas.android.com/apk/res/包名"
在xml文件里使用跟系统自带控件一样使用
类似下面的语法
myapp:vpiIconPageIndicatorStyle="xxxxx"
====================================================================================================================================================================
上边的如果要使用自定义的属性进行自定义样式
格式应该是
- <style name="Theme.PageIndicatorDefaults" parent="android:Theme">
- <item name="vpiIconPageIndicatorStyle">@style/Widget.IconPageIndicator</item>
- <item name="vpiTabPageIndicatorStyle">@style/Widget.TabPageIndicator</item>
- </style>
- //上图样式的名称是"Theme.PageIndicatorDefaults",包含两个属
- //性"vpiIconPageIndicatorStyle"和"vpiTabPageIndicatorStyle",值都是引用类型的
attr和style格式都是需要<resources>起头的
获取示例:
- TypedArray a = context.obtainStyledAttributes(null, R.styleable.ViewPagerIndicator,0, 0);
- int rsid= a.getResourceId(R.styleable.ViewPagerIndicator_vpiTabPageIndicatorStyle, 0);
- a.recycle();//必须回收
0 0
- android中自定义attr,以及style杂谈
- Android中自定义attr,以及style杂谈
- 深入理解Android 自定义attr Style styleable以及其应用
- 深入理解Android 自定义attr Style styleable以及其应用
- Android自定义attr和style
- Android 中style attr declare-styleable theme以及引用方式
- android 中的Style、Themes以及attr
- Android中 @和?区别以及?attr/**与@style/**等的区别
- Android中 @和?区别以及?attr/**与@style/**等的区别
- android 中 style="?android:attr/ratingBarStyleSmall" 是什么意思
- Android xml中 @和?区别,style和attr小结
- Android中的style,attr,theme
- Android中的style,attr,theme
- Android中的style,attr,theme
- Android中的style,attr,theme
- android attr.xml my style
- Android - Attr、Style、Theme浅析
- Android中View自定义XML属性详解以及R.attr与R.styleable的区别
- C语言 malloc realloc calloc
- 彻底理解PHP的SESSION机制
- Spring Test 整合 JUnit 4 使用总结
- hdu5726 GCD (线段树+区间gcd)
- 2016多校训练Abandoned country (最小生成树+期望)
- android中自定义attr,以及style杂谈
- 随机森立预测风险
- java③
- 如何在python中读写和存储matlab的数据文件(*.mat)
- trimmomatic 去接头,处理reads
- ssm
- Linux学习笔记--设备(主要指存储设备)挂载目录
- 【BZOJ】2048 2009国家集训队 书堆
- H5 iOS传值