Android-style&theme

概述

style 應用於 View,可以在 layout 文件中設置;

theme 本身也是 style,但應用於Activity 或 application,必須在 manifest 文件中設置;


style 的定義

自定義 style 必須放在 res/values 目錄下,文件名任意,使用<resource> <style> <item> 標籤


自定義 style 的繼承寫法

自定義 style 的繼承可以通過這種寫法實現,但不能繼承安卓內置的 style

    <style <strong>name="CodeFont.Red"</strong>>
        <item name="android:textColor">#FF0000</item>
    </style>


    <style <strong>name="CodeFont.Red.Big"</strong>>
        <item name="android:textSize">30sp</item>
    </style>


基於系統版本自動選擇 theme

通過 “res/values-vXX” 這種方法實現依據不同的系統版本應用不同的 style,並且XX及以上版本均會生效


參考

這裏查看安卓系統 style, theme  R.style "/sdk/docs/reference/android/R.style.html"

這裏查看 style 的所有屬性 R.attr "/sdk/docs/reference/android/R.attr.html"

這裏查看安卓系統 style theme 源碼



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章