zoukankan      html  css  js  c++  java
  • Android中的 style 和 theme

         通过设置 view 控件的属性,达到设置android UI的目的,如果某些 属性值复用率很高,可以考虑将属性单独声明在 style中,这样就可以达到复用的效果。

    一、style

    Style 概念:A style is a set of attributes that you can apply to a widget. 或者 A style is an XML resource that contains attributes that describe how a widget should look and behave.  一句话 sytle 是一组用于定义控件的属性集合。

    style的定义: 以标签 <style></style>来标示,定义在 res/value 目录 文件中 根标签 <resource>,其中每个属性项目使用  <item></item>标示。可以查看系统定义的一些style:在sdk安装目录下 某个sdk版本中 :platformsandroid-19data esvalues 的styles.xml 中,可以看到这里面属性名有以 android: 开头的,也有不以其开头的

      例如:

    <style name="AlertDialog">
            <item name="fullDark">@android:drawable/popup_full_dark</item>
            <item name="topDark">@android:drawable/popup_top_dark</item>
            <item name="centerDark">@android:drawable/popup_center_dark</item>
            <item name="bottomDark">@android:drawable/popup_bottom_dark</item>
            <item name="fullBright">@android:drawable/popup_full_bright</item>
            <item name="topBright">@android:drawable/popup_top_bright</item>
            <item name="centerBright">@android:drawable/popup_center_bright</item>
            <item name="bottomBright">@android:drawable/popup_bottom_bright</item>
            <item name="bottomMedium">@android:drawable/popup_bottom_medium</item>
            <item name="centerMedium">@android:drawable/popup_center_medium</item>
            <item name="progressLayout">@android:layout/progress_dialog</item>
            <item name="horizontalProgressLayout">@android:layout/alert_dialog_progress</item>
        </style>

    style的引用: 在控件中使用style 属性 指定需要引用的style  style =“@style/stylename”

     二 、theme

    Theme 概念:A theme is a collection of styles. theme 是style的集合,作用于整个APP 或者 整个Activity。

    theme 定义:在 res/values 目录文件中定义,以<resource>为根目录,方式与style相同。

        <style name="AppTheme" parent="AppBaseTheme">
            <!-- All customizations that are NOT specific to a particular API-level can go here. -->
        </style>
    

     theme的应用:在 Mainfest.xml 中 的 <appliaction> 或者 <activity> 标签中 使用  android:theme 指定 APP 或者某个 Activity的 theme。

     使用 工程中创建的theme

    <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
    

     使用系统内自带的theme

    <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.Holo.Light" >
    
  • 相关阅读:
    在循环中禁止remove/add
    [算法竞赛入门]WERTYU
    [算法竞赛入门]Tex Quotes
    [算法竞赛入门]竖式问题
    [算法竞赛入门]蛇形填数
    [C++面试]关于const的使用方法
    [C++面试]单例模式-设计模式
    [C++面试]C++的三种继承(public/protected/private继承)
    用微服务架构,有哪些好处?
    东软数据可视化分析, 已经方便成这样?!
  • 原文地址:https://www.cnblogs.com/igoogleyou/p/themesandroid.html
Copyright © 2011-2022 走看看