zoukankan      html  css  js  c++  java
  • 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();









  • 相关阅读:
    第十三周总结
    第十二周总结
    团队冲刺第十五天-KeepRunningAPP
    团队第一阶段冲刺评价
    团队项目KeepRunning第一阶段成果展示
    团队冲刺第十四天-KeepRunningAPP
    第十一周总结
    团队冲刺第十三天-KeepRunningAPP
    CVPR2018关键字生成词云图
    Delphi APP 開發入門(八)SQLite資料庫
  • 原文地址:https://www.cnblogs.com/shaofeer/p/11154392.html
Copyright © 2011-2022 走看看