Android自定义的属性的使用
获取引用类型的属性值
private void init(Context context, AttributeSet attrs) {
//int textId = attrs.getAttributeIntValue(NAME_SPACE,"text");
//String string = getResources().getString(textId);
//Log.e("UserViewView", "UserViewView init()" + textId);
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.UserViewView);
int resourceId = ta.getResourceId(R.styleable.UserViewView_text, 0);
String string = getResources().getString(resourceId);
Log.e("UserViewView", "UserViewView init()"+string);
//回收
ta.recycle();
}
<declare-styleable name="UserViewView">
<attr name="text" format="reference"/>
</declare-styleable>
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.registItemView);
String item_left = typedArray.getString(R.styleable.registItemView_item_left);
String item_btn_right = typedArray.getString(R.styleable.registItemView_item_btn_right);
String item_center = typedArray.getString(R.styleable.registItemView_item_center);
boolean item_btn_right_is_gone =
typedArray.getBoolean(R.styleable.registItemView_item_btn_right_is_gone, false);
boolean item_ib_right_is_gone =
typedArray.getBoolean(R.styleable.registItemView_item_ib_right_is_gone, false);
//获取引用类型的值
int itemBottomResourceId = typedArray.getResourceId(R.styleable.registItemView_item_bottom, 0);
String item_bottom = context.getString(itemBottomResourceId);
int item_input_type =
typedArray.getInt(R.styleable.registItemView_item_input_type, InputType.TYPE_CLASS_TEXT);
//释放
typedArray.recycle();
Android自定义的属性的使用的更多相关文章
- android自定义view属性
第一种 /MainActivity/res/values/attrs.xml <?xml version="1.0" encoding="utf-8"?& ...
- Android自定义XML属性以及遇到的命名空间的问题
转载请注明出处:http://www.cnblogs.com/kross/p/3458068.html 最近在做一些UI,很蠢很蠢的重复写了很多代码,比如一个自定义的UI Tab,由一个ImageVi ...
- android 自定义View属性
在android开发过程中,用到系统的View时候可以通过XML来定义一些View的属性.比如ImageView: android:src 和android:scaleType为ImageVie ...
- android自定义视图属性(atts.xml,TypedArray)学习
是一个用于存放恢复obtainStyledAttributes(AttributeSet, int[], int, int)或 obtainAttributes(AttributeSet, int[] ...
- Android自定义XML属性
<?xml version="1.0" encoding="utf-8"?> <resources> <declare-style ...
- Android之探究viewGroup自定义子属性参数的获取流程
通常会疑惑,当使用不同的布局方式时,子view得布局属性就不太一样,比如当父布局是LinearLayout时,子view就能有效的使用它的一些布局属性如layout_weight.weightSum. ...
- Android读取自定义View属性
Android读取自定义View属性 attrs.xml : <?xml version="1.0" encoding="utf-8"?> < ...
- Android 自定义view中的属性,命名空间,以及tools标签
昨日看到有人在知乎上问这3个琐碎的小知识点,今天索性就整理了一下,其实这些知识点并不难,但是很多开发者平时很少注意到这些, 导致的后果就是开发的时候 经常会被ide报错,开发效率很低,或者看开源代码的 ...
- Android自定义视图一:扩展现有的视图,添加新的XML属性
这个系列是老外写的,干货!翻译出来一起学习.如有不妥,不吝赐教! Android自定义视图一:扩展现有的视图,添加新的XML属性 Android自定义视图二:如何绘制内容 Android自定义视图三: ...
随机推荐
- 将Imagelist里的图像复制到TCanvas上的指定区域
function Tdmd.Draw_Image_In_Rect(C:TCanvas;R:TRect;i:integer):boolean;var tr:TRect;begin if i< ...
- tftp的安装及配置
1.安装tftp服务客户端sudo apt-get install tftp 2.安装tftp服务器端sudo apt-get install tftpd 3.安装xinetd注意同类似的还有open ...
- DHTMLEdit控件的安装
xp中自带了DHTMLEdit.ocx, 所以只需安装即可 但是可视化设计面板中没有这个控件,需要我们手动安装一下 具体方式: [import AcitveX control 在控件板上的安装]一. ...
- Aria2在Windows上如何安装配置使用
一.下载所需的软件 二.安装与使用 三.Aria2的额外内容 四.Aria2的使用 五.Aria2与其它插件配合使用 一.下载所需的软件 可以从一下地址获取最新版本 GitHub: https://g ...
- <iOS小技巧> 返回上级目录操作Goback()方法
Goback()方法功能:返回上一级界面,通过判断 popViewControllerAnimated 类型是否为空,来判断是present还是pop出来,然后直接做了releaseSelf操作: - ...
- 【算法随记三】小半径中值模糊的急速实现(16MB图7.5ms实现) + Photoshop中蒙尘和划痕算法解读。
在本人的博客里,分享了有关中值模糊的O(1)算法,详见:任意半径中值滤波(扩展至百分比滤波器)O(1)时间复杂度算法的原理.实现及效果 ,这里的算法的执行时间和参数是无关的.整体来说,虽然速度也很快, ...
- ZooKeeper学习第五期--ZooKeeper管理分布式环境中的数据(转)
转载来源:https://www.cnblogs.com/sunddenly/p/4092654.html 引言 本节本来是要介绍ZooKeeper的实现原理,但是ZooKeeper的原理比较复杂,它 ...
- 11 CSS的三种引入方式和基本选择器
<!-- 整体说明: 1.CSS的三种引入方式 (1)行内样式 (2)内接样式 (3)外接样式 2.CSS的基本选择器 (1)id选择器 (引用方式:#id) (2)标签选择器(引用方式:标签名 ...
- C语言实现贪吃蛇
日期:2018.9.11 用时:150min 项目:贪吃蛇(C语言--数组 结构体实现) 开发工具:vs2013 关键知识:数组,结构体,图形库,键位操作 源代码: #include<std ...
- Git项目迁移
代码项目迁移步骤 1.将原有项目重命名,old 2.新建一个项目,名字为原本的项目名称,new 3.使用特殊方式克隆代码 # old.git为原项目重命名后的git链接 git clone --mir ...