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 等

  • 相关阅读:
    统计学_筛选试验
    ROC、PR 曲线/准确率、覆盖率(召回)、命中率、Specificity(负例的覆盖率)、F1 score
    阳/阴性预测值Positive/negative Predictive Value(推荐AA)
    统计学_样本量估计_python代码实现
    统计学_效应量Effect Size
    统计学_二型错误和功效(Type II Errors and Test Power)
    统计学的P值解释和误区
    【线性代数的几何意义】向量的基本几何意义
    【线性代数的几何意义】什么是线性代数
    【Eclipse】如何在Eclipse中使用命令行?
  • 原文地址:https://www.cnblogs.com/wjw334/p/4457597.html
Copyright © 2011-2022 走看看