Using ActionBarActivity without getting java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity



I have seen many questions regarding this error but none seem to solve my problem. I am trying to use this costume style for "style-v21"



<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- inherit from the material theme -->
<style name="AppTheme" parent="">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="android:colorPrimary">@android:color/holo_orange_dark</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="android:colorPrimaryDark">@android:color/holo_orange_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="android:colorAccent">@android:color/holo_orange_dark</item>

<item name="android:navigationBarColor">@android:color/holo_orange_dark</item>
</style>
</resources>


I get this message in my logcat when the app tries to run



Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.


As other answers to similar questions have stated you can just switch the the Activity that uses this view from ActionBarActivity to just Activity. This does solves the error but how would I use onOptionItemSelected and other methods that allow you to interact with the action bar.


This is My mainiest `



<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"

>
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>


`


Is there a way that I can use the style and ActionBarActivity at the same time without getting this error.


No comments:

Post a Comment