首页 > 其他 > 详细

关于如何在XML中使用自定义控件。

时间:2014-03-30 08:21:37      阅读:599      评论:0      收藏:0      [点我收藏+]

1.首先创建一个类继承View或者是View的子类,根据你需要的类型进创建。

2.添加一个带两个参数的构造方法。

3. 定义自定义控件属性。如:

参照ApiDemos\res\values\attrs.xml定义属性

   <declare-styleable name="VerticalTextView">

       <attr name="content" format="string|reference" />

       <attr name="contentColor" format="color|reference" />

       <attr name="contentSize" format="dimension|reference" />

   </declare-styleable>    

4.然后在构造方法中读出你需要的内容如:

TypedArray ta = context.obtainStyledAttributes(

       attrs, R.styleable.VerticalTextView);

       mContent = ta.getString(

           R.styleable.VerticalTextView_content);


本文出自 “AsyncTask异步加载” 博客,请务必保留此出处http://3072502.blog.51cto.com/3062502/1386734

关于如何在XML中使用自定义控件。,布布扣,bubuko.com

关于如何在XML中使用自定义控件。

原文:http://3072502.blog.51cto.com/3062502/1386734

(2)
(1)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!