Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to change Appcompat theme from light to holo dark

I am trying to change the theme of my app completely, This is what I modified & tried :

styles.xml in values folder is

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

I am using ActionBarActivity & appcompat_v7 but the app crashes by 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

Am I missing something...?

How can I solve this problem?

Please help...

Thanks in advance !


EDIT: When using Appcompat theme , the theme was light, the code was:

So, using appcompat theme my styles.xml in values folder was

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

And I dont know how to change appcompat theme from light to holo dark. Please help

like image 521
Vivek Warde Avatar asked Aug 06 '14 14:08

Vivek Warde


1 Answers

As tyczj pointed, you need to use Theme.AppCompat as a parent for your themes if your app uses appcompat_v7. Theme.AppCompat is visually the same as Theme.Holo (dark).

See the article about styling the ActionBar on the Android documentation for more information.

like image 108
nstCactus Avatar answered Oct 23 '22 05:10

nstCactus