无法将Appcompat主题从浅色更改为全黑色

时间:2014-08-06 14:12:00

标签: java android android-theme android-appcompat android-actionbaractivity

我正在尝试完全改变我的应用程序的主题,这是我修改过的内容。尝试过:

值文件夹中的

styles.xml

<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.Holo">
    <!--
        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>

values-v11 styles.xml

<resources>

<!--
    Base application theme for API 11+. This theme completely replaces
    AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo">
    <!-- API 11 theme customizations can go here. -->
</style>

</resources>

values-v14 styles.xml

<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="android:Theme.Holo">
    <!-- API 14 theme customizations can go here. -->
</style>

</resources>

Mainifest.xml

<application
   .....
   android:theme="@style/AppTheme" >
   .......
</application>

我正在使用ActionBarActivity&amp; appcompat_v7,但应用程序因java.lang.RuntimeException: Unable to start activity ComponentInfo{com...}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity

而崩溃

我错过了什么......?

我该如何解决这个问题?

请帮忙......

提前致谢!


编辑:使用Appcompat主题时,主题很轻,代码是:

因此,使用appcompat主题我在值文件夹中的styles.xml

<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="Theme.AppCompat.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>

values-v11 styles.xml

<resources>

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

</resources>

values-v14 styles.xml

<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>

Mainifest.xml

<application
   .....
   android:theme="@style/AppTheme" >
   .......
</application>

而且我不知道如何将appcompat主题从光变为全黑。请帮忙

1 个答案:

答案 0 :(得分:33)

正如tyczj所指出的,如果您的应用使用Theme.AppCompat,则需要使用appcompat_v7作为主题的父级。 Theme.AppCompat在视觉上与Theme.Holo(黑暗)相同。

有关详细信息,请参阅Android文档中的article about styling the ActionBar