Android读取自定义View属性
Android读取自定义View属性
attrs.xml :
<?xml version="1.0" encoding="utf-8"?>
<resources> <declare-styleable name="MyView">
<attr name="MyViewColor" format="color"/>
</declare-styleable> </resources>
activity_main.xml :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:background="@color/background"
android:layout_width="match_parent"
android:layout_height="match_parent"> <com.my.MyView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:MyViewColor="@color/pink"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="16dp"/>
</RelativeLayout>
MyView.java :
public MyView(Context context, AttributeSet attrs) {
super(context, attrs, defStyle);
if (attrs!= null) {
TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.MyView, 0, 0);
if (attr != null) {
try {
mMyViewColor = attr.getColor(R.styleable.MyViewColor, getColor(android.R.color.white));
} finally {
attr.recycle();
}
}
}
Android读取自定义View属性的更多相关文章
- android 自定义View属性
在android开发过程中,用到系统的View时候可以通过XML来定义一些View的属性.比如ImageView: android:src 和android:scaleType为ImageVie ...
- Android之自定义View学习(一)
Android之自定义View学习(一) Canvas常用方法: 图片来源 /** * Created by SiberiaDante on 2017/6/3. */ public class Bas ...
- android自定义view属性
第一种 /MainActivity/res/values/attrs.xml <?xml version="1.0" encoding="utf-8"?& ...
- Android 创建自定义 View 的属性 (attrs) 时需要注意的问题
自定义 View 的属性并不难,可以参照官方的文档 https://developer.android.com/training/custom-views/create-view.html 但是需要注 ...
- Android之自定义View的实现
对于学习Android开发的小童鞋对于自定义View一定不会陌生,相信大家对它是又爱又恨,爱它可以跟随我们的心意设计出漂亮的效果:恨它想要完全流畅掌握,需要一定的功夫.对于初学者来说确实很不容易,网上 ...
- andorid 自定义view属性declare-styleable
1. reference:参考某一资源ID. (1)属性定义: <declare-styleable name = "名称"> <attr name = &quo ...
- Android的自定义View及View的绘制流程
目标:实现Android中的自定义View,为理清楚Android中的View绘制流程“铺路”. 想法很简单:从一个简单例子着手开始编写自定义View,对ViewGroup.View类中与绘制View ...
- android中自定义view构造函数ContentItemView(Context context, AttributeSet paramAttributeSet)的用处
自己定义一个view <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:a ...
- Android中自定义View的MeasureSpec使用
有时,Android系统控件无法满足我们的需求,因此有必要自定义View.具体方法参见官方开发文档:http://developer.android.com/guide/topics/ui/custo ...
随机推荐
- elk收集分析nginx access日志
elk收集分析nginx access日志 首先elk的搭建按照这篇文章使用elk+redis搭建nginx日志分析平台说的,使用redis的push和pop做队列,然后有个logstash_inde ...
- mysql的collation
mysql的collation大致的意思就是字符序.首先字符本来是不分大小的,那么对字符的>, = , < 操作就需要有个字符序的规则.collation做的就是这个事情,你可以对表进行字 ...
- 关于HttpHandler的相关知识总结
一.关于IHttpHandler.IsReusable 很多人不明白,这哥们到底干嘛的,估计是微软最初的一个想法--让一个对象可以一直不断地被重复使用 ,但这个想法不成熟,会带来很多隐藏问题,一个对象 ...
- NOIP模拟赛-旅行者问题 解题报告
旅行者问题 [问题描述] lahub是一个旅行者的粉丝,他想成为一个真正的旅行者,所以他计划开始一段旅行.lahub想去参观n个目的地(都在一条直道上).lahub在起点开始他的旅行.第i个目的地和起 ...
- jQuery Ajax上传文件
JS代码: //保存 function btnAdd() { var formData = new FormData($("#frm")[0]); $.ajax({ url: &q ...
- 【要什么自行车】ASP.NET MVC4笔记03:调用编辑器 kindeditor
参考:http://www.cnblogs.com/guzhongx/p/kindeditor.html 1.下载kindeditor,存放于Content文件夹下 <script src=&q ...
- Oracle Error - "OCIEnvCreate failed with return code -1 but error message text was not available".
ISSUE: When trying to connect to an Oracle database you receive the following error: "OCIEnvCre ...
- java for 的用法总结
J2SE 1.5提供了另一种形式的for循环.借助这种形式的for循环,可以用更简单地方式来遍历数组和Collection等类型的对象.本文介绍使用这种循环的具体方式,说明如何自行定义能被这样遍历的类 ...
- 第二讲:WCF介绍(2)
代码 https://yunpan.cn/cPns5DkGnRGNs 密码:3913 在上一讲中我们说到 在代码 当中 完成了 服务的寄宿. 这里我们说下 在实际的开发 当中 我们一般不会去 ...
- font-family常见字体
font-family:"Times New Roman",Georgia,Serif font-family:Arial,Verdana,Sans-serif font-fami ...