D
D
dangerclose2014-06-01 19:24:19
Android
dangerclose, 2014-06-01 19:24:19

How to fix error when changing theme?

Here is the manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.dsds"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.Example" >
        <activity
            android:name="com.example.dsds.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

here is the topic
<?xml version="1.0" encoding="utf-8"?>
<!-- File created by the Android Action Bar Style Generator

     Copyright (C) 2011 The Android Open Source Project
     Copyright (C) 2012 readyState Software Ltd

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at
  
          http://www.apache.org/licenses/LICENSE-2.0
  
     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<resources>

    <style name="Theme.Example" parent="@android:style/Theme.Holo.Light.DarkActionBar">
        <item name="android:actionBarItemBackground">@drawable/selectable_background_example</item>
        <item name="android:popupMenuStyle">@style/PopupMenu.Example</item>
        <item name="android:dropDownListViewStyle">@style/DropDownListView.Example</item>
        <item name="android:actionBarTabStyle">@style/ActionBarTabStyle.Example</item>
        <item name="android:actionDropDownStyle">@style/DropDownNav.Example</item>
        <item name="android:actionBarStyle">@style/ActionBar.Solid.Example</item>
        <item name="android:actionModeBackground">@drawable/cab_background_top_example</item>
        <item name="android:actionModeSplitBackground">@drawable/cab_background_bottom_example</item>
        <item name="android:actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Example</item>
        
                <!-- Light.DarkActionBar specific -->
        <item name="android:actionBarWidgetTheme">@style/Theme.Example.Widget</item>

    </style>

    <style name="ActionBar.Solid.Example" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
        <item name="android:background">@drawable/ab_solid_example</item>
        <item name="android:backgroundStacked">@drawable/ab_stacked_solid_example</item>
        <item name="android:backgroundSplit">@drawable/ab_bottom_solid_example</item>
        <item name="android:progressBarStyle">@style/ProgressBar.Example</item>
    </style>

    <style name="ActionBar.Transparent.Example" parent="@android:style/Widget.Holo.ActionBar">
        <item name="android:background">@drawable/ab_transparent_example</item>
        <item name="android:progressBarStyle">@style/ProgressBar.Example</item>
    </style>

    <style name="PopupMenu.Example" parent="@android:style/Widget.Holo.ListPopupWindow">
        <item name="android:popupBackground">@drawable/menu_dropdown_panel_example</item>	
    </style>

    <style name="DropDownListView.Example" parent="@android:style/Widget.Holo.ListView.DropDown">
        <item name="android:listSelector">@drawable/selectable_background_example</item>
    </style>

    <style name="ActionBarTabStyle.Example" parent="@android:style/Widget.Holo.ActionBar.TabView">
        <item name="android:background">@drawable/tab_indicator_ab_example</item>
    </style>

    <style name="DropDownNav.Example" parent="@android:style/Widget.Holo.Spinner">
        <item name="android:background">@drawable/spinner_background_ab_example</item>
        <item name="android:popupBackground">@drawable/menu_dropdown_panel_example</item>
        <item name="android:dropDownSelector">@drawable/selectable_background_example</item>
    </style>
    
    <style name="ProgressBar.Example" parent="@android:style/Widget.Holo.ProgressBar.Horizontal">
        <item name="android:progressDrawable">@drawable/progress_horizontal_example</item>
    </style>
    
    <style name="ActionButton.CloseMode.Example" parent="@android:style/Widget.Holo.ActionButton.CloseMode">
        <item name="android:background">@drawable/btn_cab_done_example</item>
    </style>

    <!-- this style is only referenced in a Light.DarkActionBar based theme -->
    <style name="Theme.Example.Widget" parent="@android:style/Theme.Holo">
        <item name="android:popupMenuStyle">@style/PopupMenu.Example</item>
        <item name="android:dropDownListViewStyle">@style/DropDownListView.Example</item>
    </style>

</resources>

here is the error code
06-01 16:20:29.867: E/AndroidRuntime(340): FATAL EXCEPTION: main
06-01 16:20:29.867: E/AndroidRuntime(340): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.dsds/com.example.dsds.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
06-01 16:20:29.867: E/AndroidRuntime(340): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
06-01 16:20:29.867: E/AndroidRuntime(340): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
06-01 16:20:29.867: E/AndroidRuntime(340): 	at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-01 16:20:29.867: E/AndroidRuntime(340): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
06-01 16:20:29.867: E/AndroidRuntime(340): 	at android.os.Handler.dispatchMessage(Handler.java:99)
06-01 16:20:29.867: E/AndroidRuntime(340): 	at android.os.Looper.loop(Looper.java:123)
06-01 16:20:29.867: E/AndroidRuntime(340): 	at android.app.ActivityThread.main(ActivityThread.java:3683)
06-01 16:20:29.867: E/AndroidRuntime(340): 	at java.lang.reflect.Method.invokeNative(Native Method)
06-01 16:20:29.867: E/AndroidRuntime(340): 	at java.lang.reflect.Method.invoke(Method.java:507)
06-01 16:20:29.867: E/AndroidRuntime(340): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-01 16:20:29.867: E/AndroidRuntime(340): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-01 16:20:29.867: E/AndroidRuntime(340): 	at dalvik.system.NativeStart.main(Native Method)
06-01 16:20:29.867: E/AndroidRuntime(340): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
06-01 16:20:29.867: E/AndroidRuntime(340): 	at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:108)
06-01 16:20:29.867: E/AndroidRuntime(340): 	at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
06-01 16:20:29.867: E/AndroidRuntime(340): 	at com.example.dsds.MainActivity.onCreate(MainActivity.java:18)
06-01 16:20:29.867: E/AndroidRuntime(340): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-01 16:20:29.867: E/AndroidRuntime(340): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
06-01 16:20:29.867: E/AndroidRuntime(340): 	... 11 more

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
anyd3v, 2014-06-01
@anyd3v

I guess right away, because I saw such an error. The problem is using ActionBar from the support library.
This is written in the documentation: developer.android.com/reference/android/support/v7...
When using the support library, you can add the action bar to the top of your activity window by extending the ActionBarActivity class and setting the activity theme to Theme.AppCompat or a similar theme.
Accordingly, you need to do this
+ there are a couple more themes with dark / light variations

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question