Search code examples
androidandroid-actionbarmaterial-designandroid-5.0-lollipop

Android 5.0 API 21 application files contain AppCompat references


I am trying to learn well the structure of Android application sources. I created a new project in Android Studio. I want to use the latest features of the material design and at this point I don't think about compatibility with earlier Android versions. So I selected Minimum SDK - "API 21: Android 5.0 (Lollipop)". Then I selected "Fullscreen Activity". The first exception is "Rendering problems. The following classes could not be found: android.support.v7.internal.app.WindowDecorActionBar" when I try to open activity_fullscreen.xml. In the build.gradle I removed two last lines from dependencies:

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
}

Then I got a build error:

Error:(2) Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'.

I configured the 'styles.xml' to use the Material theme instead of "Theme.AppCompat.Light.DarkActionBar"

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

But one error is still present:

Error:(2) Error retrieving parent for item: No resource found that matches the given name 'Widget.AppCompat.ActionBar'.

in the Action bar style definition

<style name="FullscreenActionBarStyle" parent="Widget.AppCompat.ActionBar">
    <item name="android:background">@color/black_overlay</item>
</style>

I don't know how to set up action bar without support library. Why my project does need it at all? The documentation I read describes action bar setup only with AppCompat. Or Material theme does not provide action bar at all? Why appcompat-v7 references are present in the sources since I selected minimum SDK 21? I am really confused because I am not able to build even a simplest project.


Solution

  • It's probably because Android Studio does not have different templates based on API level, it just uses AppCompat everywhere.

    Replace Widget.AppCompat.ActionBar with Widget.ActionBar or even better, remove FullscreenActionBarStyle and all references to it and use the system default.