编程语言
首页 > 编程语言> > java – 无法将Appcompat主题从light更改为holo dark

java – 无法将Appcompat主题从light更改为holo dark

作者:互联网

我试图完全改变我的应用程序的主题,这是我修改过的&尝试过:

values文件夹中的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& appcompat_v7但应用程序因java.lang.RuntimeException崩溃:无法启动活动ComponentInfo {com …}:java.lang.IllegalStateException:您需要将Theme.AppCompat主题(或后代)与此活动一起使用

我错过了什么……?

我怎么解决这个问题?

请帮忙…

提前致谢 !

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

所以,使用appcompat主题我在values文件夹中的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主题从光变为全黑.请帮忙

解决方法:

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

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

标签:android-actionbaractivity,android,java,android-theme,android-appcompat
来源: https://codeday.me/bug/20191006/1861355.html