0

I have to port an application to Lollipop using material design. When I run the ported app I have the following error:

Caused by: java.lang.IllegalArgumentException: AppCompat does not support the current theme features
at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:363)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:246)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)

To port the app I created a project with Android Studio that implements toolbar and navigation drawer. The code uses a hierarchy of Activities, I let the upper base class inherit from AppCompatActivity and implement NavigationView.OnNavigationItemSelectedListener. OnNavigationItemSelectedListener returns true for the intermediate classes in the hierarchy and the final sub activity implements it. Gradle raised no errors.

For the main activity the layout consists only on a ListView and menu items. I used the default layout generated by Android Studio and set my ListView in the content_main.xml file. As listView is not supported by CoordinatorLayout, when I instanciate the listView I added (as quoted here)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    mListMain.setNestedScrollingEnabled(true);
}

I found this topic which seems to speak about the same exception. However my style files follows the recommandations that were made in the topic.

styles.xml:

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <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" />
</resources>

styles.xml(v21):

<resources>    
    <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>
</resources>

In the Manifest using either AppTheme or AppTheme.NoActionBar makes no differences

The exception is raised on the setContentView line in the MainActivity, my layouts are the one created by Android Studio except the content_main file

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>

app_bar_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="aklal.org.materialclient.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_main" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>

content_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="aklal.org.materialclient.MainActivity"
    tools:showIn="@layout/app_bar_main">

    <ListView
        android:id="@+id/listMainAct"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </ListView>
</RelativeLayout>

Any idea on what is going wrong? Any help would be highly appreciated

Edit: What I do not understand is that even if I comment everything (in layout and code) related to the listView, the exception is still raised

Edit: It seems that the problem comes from the code, I will give the solution when I find it

Community
  • 1
  • 1
eqtèöck
  • 971
  • 1
  • 13
  • 27

1 Answers1

0

Based on this line Appcompat does not support the current theme features .Appcompat version using in your app not supported the lollipop theme features so only it raising exception.

Your using lollipop ported application but not used the correct version of appcompat. Instead of using appcompat-v7:22.2.1.Use following dependency in your gradle file and try.

          compile 'com.android.support:appcompat-v7:23.1.1'
KCN
  • 472
  • 6
  • 19
  • Unfortunatly it is not possible for me to use 23.1.1 because the app is using an apache HttpClient lib that has some of [these classes deleted with api23](http://stackoverflow.com/questions/32180500/android-api-23-removed-packages). There are some [solutions](http://stackoverflow.com/questions/32153318/httpclient-wont-import-in-android-studio) but I cannot afford to recode all the classes with another http client, so I have to try to find a solution to let the app run with api22. – eqtèöck Jan 14 '16 at 21:52