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

    1.定义 

    attr.xml中定义 

    <resources>
        <declare-styleable name="ViewFlow">
            <attr name="sidebuffer" format="integer" />
        </declare-styleable>
        <declare-styleable name="CircleFlowIndicator">
            <attr name="activeColor" format="color" />
            <attr name="inactiveColor" format="color" />
            <attr name="radius" format="dimension" />
            <attr name="spacing" format="dimension" />
            <attr name="centered" format="boolean" />
            <attr name="fadeOut" format="integer" />
            <attr name="inactiveType">
                <flag name="stroke" value="0" />
                <flag name="fill" value="1" />
            </attr>
            <attr name="activeType">
                <flag name="stroke" value="0" />
                <flag name="fill" value="1" />
            </attr>
            <attr name="snap" format="boolean" />
        </declare-styleable>    
        <declare-styleable name="TitleFlowIndicator">
            <attr name="titlePadding" format="dimension" />
            <!-- Left/right padding of not active view titles. -->
            <attr name="clipPadding" format="dimension" />
            <attr name="selectedColor" format="color" />
            <attr name="selectedBold" format="boolean" />
            <attr name="selectedSize" format="dimension" />
            <attr name="textColor" format="color" />
            <attr name="textSize" format="dimension" />
            <attr name="footerLineHeight" format="dimension" />
            <attr name="footerColor" format="color" />
            <attr name="footerTriangleHeight" format="dimension" />
            <attr name="customTypeface" format="string" />
        </declare-styleable>    
    </resources>

    相关字段

    resources -> declare-styleable ->attr( name ,format (color,dimension,boolean,string,integer,))  or -> flag(name,value)

    2.layout中的使用

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res/org.taptwo.android.widget.viewflow.example"
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    
        <org.taptwo.android.widget.CircleFlowIndicator
            android:padding="10dip"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:id="@+id/viewflowindic"
            android:layout_gravity="center_horizontal"
            app:inactiveType="fill"
            app:fadeOut="1000" />
        <org.taptwo.android.widget.ViewFlow
            android:id="@+id/viewflow" android:layout_width="fill_parent"
            android:layout_height="fill_parent" app:sidebuffer="3"></org.taptwo.android.widget.ViewFlow>
    
    </FrameLayout>

      1.xmlns:app="http://schemas.android.com/apk/res/org.taptwo.android.widget.viewflow.example"   

      app为自定义标签前缀 路径为 http://schemas.android.com/apk/res + 资源路径(包名)

      2.app:inactiveType="fill"   app:fadeOut="1000"  app:textColor="#FFFFFFFF"  app:footerTriangleHeight="10dp" app:customTypeface="fonts/Antic.ttf"

     如上定义  inactivieType是自定义类型 fadeOut是integer类型 textColor是color类型 footerTriangleHeight是dimension类型  customTypeface是string类型
    3.view中读取
        TypedArray a = context.obtainStyledAttributes(attrs,
                    R.styleable.CircleFlowIndicator);
    
            // Gets the active circle type, defaulting to "fill"
            int activeType = a.getInt(R.styleable.CircleFlowIndicator_activeType,
                    STYLE_FILL);
            
            int activeDefaultColor = 0xFFFFFFFF;
            
            // Get a custom active color if there is one
            int activeColor = a
                    .getColor(R.styleable.CircleFlowIndicator_activeColor,
                            activeDefaultColor);

    如上 1.obtion TypedArray 2.getInt getColor 等

  • 相关阅读:
    MYSQL/HIVESQL笔试题(一):HIVESQL(一)分组求TopN/行转列/列转行
    ALINK(七):ALINK使用技巧(二)
    Hive实战(6):完整案例(二)业务分析
    Hive实战(5):完整案例(一)准备
    Mysql基础(二十四):数据类型/常见约束
    Mysql基础(二十三):视图/存储过程
    数据可视化基础专题(三十四):Pandas基础(十四) 分组(二)Aggregation/apply
    Daily Coding Problem: Problem #677
    1027. Longest Arithmetic Subsequence (Solution 1)
    346. Moving Average from Data Stream
  • 原文地址:https://www.cnblogs.com/wjw334/p/4457597.html
Copyright © 2011-2022 走看看