簡體   English   中英

將android:Theme.Light更改為Theme.AppCompat.Light.DarkActionBar

[英]change android:Theme.Light to Theme.AppCompat.Light.DarkActionBar

我有在android:Theme.Light中創建的應用程序。 我想將它更改為Theme.AppCompat.Light.DarkActionBar,但我得到

找不到與給定名稱'theme.appcompat.light.darkactionbar'匹配的資源

我有android-support-v4.jar,當我嘗試添加appcompat_v7時,我在代碼中得到錯誤就像是它......我可以將DarkActionBar添加到這個項目而不會出現代碼問題嗎? 沒有代碼更改?

我有:

<resources>

    <!--
        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. -->
    </style>

</resources>

我想要:

<resources>

    <!--
        Base application theme for API 14+. This theme completely replaces
        AppBaseTheme from BOTH res/values/styles.xml and
        res/values-v11/styles.xml on API 14+ devices.
    -->
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- API 14 theme customizations can go here. -->
    </style>

</resources>

確保您的應用程序與支持庫正確鏈接,並附帶資源( 請參閱此處的文檔 )。

別忘了@style/

<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">

這將防止發生no resource錯誤。 您可能也對本教程感興趣。

如果您在清單中執行此操作,請執行以下操作為整個應用設置主題:

 <application
    ...
    android:theme="@style/Theme.AppCompat.Light.DarkActionBar" 
    ...>

在您的XML中針對特定主題,您需要@style ,因此請執行以下操作:

<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM