0

I'm developing an Android Library module, and I'd like to use Material Design. But if I include my library in another app that uses pre-Material ActionBar, I got this error:

java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.

I am able to make the error disappear only if the 'parent' app also uses a Toolbar instead of an ActionBar, i.e. if it's also themed with Material Design.

I want to allow any app to use this library, no matter what theme they're using.

In my library I included the appCompat lib and made it compatible back to Jelly Bean, according to all the guidelines. Is there some way to prevent the parent app's theme from pervading and demanding the window decor?

ygesher
  • 1,133
  • 12
  • 26
  • Possible duplicate of [This Activity already has an action bar supplied by the window decor](http://stackoverflow.com/questions/26515058/this-activity-already-has-an-action-bar-supplied-by-the-window-decor) – Bharatesh May 16 '16 at 08:20
  • @skadoosh No, there are about a dozen questions on SO similar to that one, but all are dealing with the problem within a single module. – ygesher May 16 '16 at 08:21
  • 1
    i think the problem is with styles. Create a base theme in lib module and use it in the app module. – Riyaz Ahamed May 16 '16 at 08:24
  • @RiyazAhamed I did that, as I stated, the library itself complies with all the AppCompat guidelines. It's the parent app that's using the library that's causing the problem, and I want to prevent that from happening, without having any direct control over which parent app uses my library. – ygesher May 16 '16 at 11:58

1 Answers1

0

Check your styles.xml .. It should have something like this:

<style name="AppTheme" parent="MyMaterialTheme">
    <!-- Customize your theme here. -->
</style>

<style name="MyMaterialTheme" parent="MyMaterialTheme.Base">

</style>

<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
</style>

And on your AndroidManifest.xml set activity theme: AppTheme

  • Please read the question again. My library works fine, I just want anyone to be able to use it in their app, no matter what theme they are using. – ygesher May 16 '16 at 08:52