Material Design support below Lollipop - crashes
Asked Answered
H

5

4

I've been trying to implement the Material Design theme, following these instructions.

  • I'm not using ToolBar (must I?)
  • ALL my Activities extends ActionBarActivity.
  • Using getSupportActionBar() all across the project.
  • I'm compiling and targeting to API 21 in gradle (minimun is API 15).
  • My <application> tag contains android:theme="@style/AppTheme"
  • Running the application on Lollipop device (with a specific v21 similar theme works).

My styles.xml:

<style name="AppBaseTheme" parent="@style/Theme.AppCompat">
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->

</style>

<style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar.Solid">
     <item name="displayOptions">useLogo|showHome</item>
    <item name="logo">@drawable/home_page_logo</item>
    <item name="background">@color/actionbar_background_color</item>
    <item name="textColor">@color/white</item>
    <item name="titleTextStyle">@style/MyActionBarTextStyle</item>
</style>

No matter what I tried, the application crashes the second I launch my main activity on onCreate() with this crash log:

Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:151)
 at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:138)
 at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)

Did anyone experience this issue? any suggestions on what might cause this?

Edit: It's definitely something in my styles.xml theme. If I force the app to use the default Theme.AppCompat theme, it works. What might cause a theme to fail? I verified the ActionBar attributes are not using "android:". Anything else?

Hypocaust answered 17/2, 2015 at 20:45 Comment(2)
@PearsonArtPhoto yeah... verified again. All modules are targeting v21.Hypocaust
@PearsonArtPhoto clean, rebuild, gradle sync... basically everythingHypocaust
H
11

SOLVED...

2 of my jar libs apparently have generated values.xml that contains styles of both AppTheme and AppBaseTheme. I verified only our dependencies modules, as jar libraries shouldn't declare application themes, specially not with the name of the default ones.

Before posting the answer, I added to my AndroidManifest.xml <application> tools:replace="android:theme" and declared the new theme, assuming it'll work and my application will override any other theme.

The solution eventually, stupid as it is, was to rename my own AppTheme and AppBaseTheme to different names and now it works. Hours spent on such a trivial fix. Hopefully, this will spare some time for others.

Hypocaust answered 18/2, 2015 at 7:29 Comment(0)
B
2

parent should be Theme.AppCompat not @style/Theme.AppCompat.

Using @style/ you'll be using the style from the Android API 21, and it must be the style from the AppCompat library.

edit:

probably same thing for the Widget.AppCompat

edit2:

like this

<style name="AppBaseTheme" parent="Theme.AppCompat">
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->

</style>

<style name="MyActionBar" parent="Widget.AppCompat.ActionBar.Solid">
     <item name="displayOptions">useLogo|showHome</item>
    <item name="logo">@drawable/home_page_logo</item>
    <item name="background">@color/actionbar_background_color</item>
    <item name="textColor">@color/white</item>
    <item name="titleTextStyle">@style/MyActionBarTextStyle</item>
</style>
Beecher answered 17/2, 2015 at 21:11 Comment(4)
Thanks. Tried that as well, for all parents.Hypocaust
that's super weird. Getting to work tomorrow I'll check how's on our appBeecher
very weird... I'm starting to think it's related to a bad jar library that generates a values.xml with a Holo theme.Hypocaust
did you try using Theme.Material.AppCompat (I'm writing just by what I remember, it might be slightly different, but I remember that such a thing exists.)Beecher
R
1

Try remove the "@style/" from the first line in the styles.xml so you have:

<style name="AppBaseTheme" parent="Theme.AppCompat">
Robot answered 17/2, 2015 at 21:11 Comment(0)
G
1

In my case, my themes.xml had the following:

style name="Theme.DollarBucket" parent="android:Theme.Material.Light.NoActionBar" />

for some weird reason there was an "android:" tag, removing that solved my issue.

Galligaskins answered 9/5, 2023 at 16:41 Comment(0)
S
0

It happened to me when I tried to import a decomplied apk from an old project I had into a new empty app. By comparing the code to a working app, I noticed my Application node is missing a theme attribute. The error message should have been better. I added a theme to the application node in the androidmanifest.xml:

    <application android:label="@string/app_name" android:icon="@drawable/ic_launcher_foreground"
    android:theme="@style/Theme.Historia">
Shortie answered 13/4 at 17:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.