zoukankan      html  css  js  c++  java
  • Android开发学习笔记-自定义组合控件的过程

    自定义组合控件的过程

    1.自定义一个View 一般来说,继承相对布局,或者线性布局 ViewGroup;
    2.实现父类的构造方法。一般来说,需要在构造方法里初始化自定义的布局文件;
    3.根据一些需要或者需求,定义一些API方法;

    ----------------------------------
    4.根据需要,自定义控件的属性,可以参照TextView属性;

    5.自定义命名空间,例如:
    xmlns:itheima="http://schemas.android.com/apk/res/《包名》"
    xmlns:itheima="http://schemas.android.com/apk/res/com.itheima.mobilesafe"

    6.自定义我们的属性,在Res/values/attrs.xml

    <?xml version="1.0" encoding="utf-8"?>
    <resources>

    <declare-styleable name="TextView">
    <attr name="title" format="string" />
    <attr name="desc_on" format="string" />
    <attr name="desc_off" format="string" />
    </declare-styleable>

    </resources>

    7.使用我们自定义的属性
    例如:
    itheima:title="设置自动更新"
    itheima:desc_on="设置自动更新已经开启"
    itheima:desc_off="设置自动更新已经关闭"

    8.在我们自定义控件的带有两个参数的构造方法里AttributeSet attrs 取出我们的属性值,关联自定义布局文件对应的控件;

  • 相关阅读:
    flash播放器插件与flash播放器的区别
    FLASH动作脚本详解
    flash代码
    LitJson使用中需要注意的一些问题(转)
    AS3中ASCII码和字符互转函数
    JQuery直接调用asp.net后台WebMethod方法(转)
    C#文件操作
    js延迟执行
    js操作表格、table、
    定时任务、js定时任务
  • 原文地址:https://www.cnblogs.com/xuhongfei/p/4014722.html
Copyright © 2011-2022 走看看