zoukankan      html  css  js  c++  java
  • Android 自定义属性

    values新建一个attrs.xml
    <resource>
        <declare-styleable name = "MyTextView">
        <attr name="title" format="string"/>
        <attr name="switch_on" format="string"/>
        </declare-styleable>
    </resource>

    布局文件中

    自定义命名空间  res后面接包名

    xmlns:exayong="http://schemas.android.com/apk/res/com.exayong.abc"

    <MyTextView

    exayong:title="hello"

    exayong:switch_on="on"

    />

    MyTextView.java中 extends RelativeLayout

    带属性的构造方法

    attrs.getAttributeName(index);

    //获取自定义 命名空间,属性的名字

    attrs.getAttributeValue(namespace,name);

    String myTitle = attrs.getAttributeValue("http://schemas.android.com/apk/res/com.exayong.abc","title");

    1 自定义一个View 继承ViewGroup

    2 编写组合控件的布局文件,在自定义View中加载 inflate

    总结:

    把自带的view的某些属性的值 以自定义属性的方式 静态地写在布局文件中,

    然后通过自定义view inflate  findviewById -->view 如TextView

    通过自定义view带attrs的构造函数中 获取 自定义属性的值

    再通过自带的view的方法把这些值设置到自带的view的某些属性中去比如TextView.setText(myTitle);

  • 相关阅读:
    登陆跳转回原来页面
    magento获取当前浏览器的url和对url判断处理
    Magento获取购物车所有信息
    magento查询商品库存
    金额转换成0.00的形式
    Magento网站运行原理解析
    linux下如何禁用root账户直接登陆
    web前端常用的10个jQuery特效总结
    js函数
    网站css
  • 原文地址:https://www.cnblogs.com/exayong/p/6079307.html
Copyright © 2011-2022 走看看