Android自定義attr,format詳解

屬性名稱使用小駝峰命名規則

  1. reference:某一資源的id
    ImageView 的src屬性
  2. color:色值
    TextView 的textColor屬性
  3. boolean: 布爾值
    Button 的focusable屬性
  4. dimension: 尺寸值
    View 的layout_width
  5. float:浮點值
    ImageView 的 alpha屬性
  6. integer: 整型
    TextView 的 maxLines
  7. string: 字符串
    TextView 的text屬性
  8. fraction: 百分數
    rotate動畫 的pivotX屬性
  9. enum:枚舉值
    LinearLayout的orientatin屬性vertical/horizontal
  10. flag:位或運算
    activity的windowSoftInputMode屬性

屬性定義時可以指定多種類型值:

<declare-styleable name = "名稱">
         <attr name = "background" format = "reference|color" />
</declare-styleable>

自定義屬性

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容