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

Viv*_*rde 12 java android android-appcompat android-theme android-actionbaractivity

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

styles.xml 在values文件夹中

<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>
Run Code Online (Sandbox Code Playgroud)

值-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>
Run Code Online (Sandbox Code Playgroud)

值-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>
Run Code Online (Sandbox Code Playgroud)

Mainifest.xml

<application
   .....
   android:theme="@style/AppTheme" >
   .......
</application>
Run Code Online (Sandbox Code Playgroud)

我正在使用ActionBarActivity&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>
Run Code Online (Sandbox Code Playgroud)

值-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>
Run Code Online (Sandbox Code Playgroud)

值-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>
Run Code Online (Sandbox Code Playgroud)

Mainifest.xml

<application
   .....
   android:theme="@style/AppTheme" >
   .......
</application>
Run Code Online (Sandbox Code Playgroud)

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

nst*_*tus 35

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

有关详细信息,请参阅有关在Android文档中设置ActionBar样式文章.

  • 你使用了`Theme.AppCompat.Light`和`Theme.AppCompat.Light.DarkActionBar`.你试过'Theme.AppCompat`吗?我在我正在开发的应用程序中使用它,它也使用了'appcompat_v7`,它肯定是黑暗的. (11认同)