android:theme決定AlertDialog的背景顏色


最近遇到一個很奇怪的問題,兩個項目彈出的dialog背景顏色不一樣,一個是黑色的,一個是白色的,最后發現是AndroidManifest.xml文件里面application指定的android:theme設置的樣式不一樣。



黑色dialog背景效果圖:


dialog是黑色的時候application指定的樣式如下:

    <!-- Application theme. -->
    <style name="AppTheme" parent="android:Theme.Light">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
        <item name="android:windowNoTitle">true</item>
    </style>







白色背景如圖:


dialog是白色背景的時候application指定的樣式如下:

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="android:Theme.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
        <item name="android:windowNoTitle">true</item>
    </style>








總結:對比兩個樣式,我們很明顯的發現白色背景多繼承了一層,增加了AppBaseTheme樣式............希望我的總結能讓你們少遇到坑。。。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM