android style的繼承方式 點(.)和parent

來源:互聯網
上載者:User

一.概述

   
通過繼承機制,可以利用已有的style來定義新的style。所定義的新的style型不僅擁有新定義的item,而且還同時擁有舊的item。我們稱已存在的用來派生新的style為父style。由新定義的style,又稱為子style。    比如:

   

<style name="pickprof_guide_text">        <item name="android:textSize">16.0sp</item>        <item name="android:textColor">#ff333333</item></style><style name="pickprof_guide_text_small" parent="@style/pickprof_guide_text">        <item name="android:textSize">13.0sp</item>       </style>

二、兩種繼承方式

    方式一:通過parent屬性用來繼承android已經定義好的style。例如: 
    

 <style name="XDialog" parent="android:Theme.Dialog">        <item name="android:windowBackground">@drawable/pop_frame</item> </style>           

  方式二:如果要繼承自訂的style,不需要通過parent屬性,只要style的name以需要繼承的style的name開始後跟新的style的name,中間用“.”隔開。注意:這種方式只適用與自訂的style繼承。例如:  

 <!-- Base style for animations.  This style specifies no animations. -->    <style name="Animation" /> <!-- Standard animations for a non-full-screen window or activity. -->    <style name="Animation.Dialog">        <item name="windowEnterAnimation">@anim/dialog_enter</item>        <item name="windowExitAnimation">@anim/dialog_exit</item>    </style>


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.