0
votes

I had my app in production which had support from API 8+ to 23. I recently updated the app to have material design which used navigation drawer. This version had support from 14+ to 23.

The app is working fine on API 21 [ lollipop ] and above, however, there are crash reports for 4.4 "java illegalstateexception android.support.v7.app.AppCompatDelegateImplV7.createSubDecor"

My style.xml is

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

My style.xml-v21 is

>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

The manifest file is

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".View.MainActivity"
        android:label="@string/app_name"
        android:theme="@style/Theme.AppCompat.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

The mainactivity extends,

public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {

The log cat error is below

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.XYZ/com.XYZ.View.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2200) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2249) at android.app.ActivityThread.access$800(ActivityThread.java:141) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5113) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:310) at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:279) at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:253) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109) at com.XYZ.View.MainActivity.onCreate(MainActivity.java:62) at android.app.Activity.performCreate(Activity.java:5248) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2164) ... 11 more

Any help on how to handle this error would be much appreciated. I have already looked around the similar issue cases listed here but could not get this fixed.

  1. Is it possible to have Navigation drawer in API less than 21?

  2. What changes should be made in style.xml to support backward compatibility?

  3. I tried android:theme="@style/Theme.AppCompat.NoActionBar"> in MainActivity, result was in API 21 Navigation drawer worked properly expect for rendering usual theme color. In API 19, the app worked without crashing but the navigation bar went off totally which would mean only the main activity was visible to user.

Thanks for your time in advance.

1

1 Answers

0
votes

Issue fixed. Created a sample navigation drawer project - While checking found that some of the items in my project and the sample had differences. Matched the style.xml and custom content_main.xml. Now navigation drawer works fine on 14+ as well.

modified Style.xml

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />