Change the theme of Activity

Asked

Viewed 1,989 times

3

I try to change my theme to @android:style/Theme.Holo.Light in Androidmanifest but when the app runs on an emulator it stops working.
I followed a video lesson and it’s exactly the same. I don’t know what it might be.

In the logcat what appears is this:

04-01 17:31:36.998: D/AndroidRuntime(1916): Shutting down VM
04-01 17:31:36.998: W/dalvikvm(1916): threadid=1: thread exiting with uncaught exception (group=0xb3e52908)
04-01 17:31:36.998: E/AndroidRuntime(1916): FATAL EXCEPTION: main
04-01 17:31:36.998: E/AndroidRuntime(1916): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.licencasnobre/com.example.licencasnobre.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
04-01 17:31:36.998: E/AndroidRuntime(1916):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
04-01 17:31:36.998: E/AndroidRuntime(1916):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-01 17:31:36.998: E/AndroidRuntime(1916):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-01 17:31:36.998: E/AndroidRuntime(1916):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-01 17:31:36.998: E/AndroidRuntime(1916):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-01 17:31:36.998: E/AndroidRuntime(1916):     at android.os.Looper.loop(Looper.java:137)
04-01 17:31:36.998: E/AndroidRuntime(1916):     at android.app.ActivityThread.main(ActivityThread.java:5039)
04-01 17:31:36.998: E/AndroidRuntime(1916):     at java.lang.reflect.Method.invokeNative(Native Method)
04-01 17:31:36.998: E/AndroidRuntime(1916):     at java.lang.reflect.Method.invoke(Method.java:511)
04-01 17:31:36.998: E/AndroidRuntime(1916):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-01 17:31:36.998: E/AndroidRuntime(1916):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-01 17:31:36.998: E/AndroidRuntime(1916):     at dalvik.system.NativeStart.main(Native Method)
04-01 17:31:36.998: E/AndroidRuntime(1916): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
04-01 17:31:36.998: E/AndroidRuntime(1916):     at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:152)
04-01 17:31:36.998: E/AndroidRuntime(1916):     at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:149)
04-01 17:31:36.998: E/AndroidRuntime(1916):     at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
04-01 17:31:36.998: E/AndroidRuntime(1916):     at com.example.licencasnobre.MainActivity.onCreate(MainActivity.java:12)
04-01 17:31:36.998: E/AndroidRuntime(1916):     at android.app.Activity.performCreate(Activity.java:5104)
04-01 17:31:36.998: E/AndroidRuntime(1916):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
04-01 17:31:36.998: E/AndroidRuntime(1916):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
04-01 17:31:36.998: E/AndroidRuntime(1916):     ... 11 more

What is in mine AndroidManifest.xml :

`

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="21" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.Holo.Light" >
    <activity
        android:name=".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>

And what’s in my file 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.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>

1 answer

2

You must be using appcompat lib.

When a Activity descended from ActionBarActivity may only use the following Theme

1 -Theme.Appcompat
2 -Theme.AppCompat.Light
3 -Theme.AppCompat.Light.Darkactionbar

In the Androidmanifest.xml place:

android:theme="@style/AppTheme"

In the Styles.xml if you choose option 3:

<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar"/>
  • Got it. How do I change it? I’m new to android programming...

  • I edited the answer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.