Dan653
Dan653

Reputation: 3

Java Eclipse Theme.AppCompat error

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="net.androidbootcamp.concerttickets2"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="net.androidbootcamp.concerttickets2.MainActivity"
            android:theme="@android:style/Theme.Black.NoTitleBar"
            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>

</manifest>

Why am I getting an error that says I need to use a Theme.AppCompat theme (or descendent) with this activity? I am trying to run this on API 19.

Upvotes: 0

Views: 202

Answers (2)

betorcs
betorcs

Reputation: 2821

    <activity
        android:name="net.androidbootcamp.concerttickets2.MainActivity" <-- If this guy extends ActionBarCompat -->
        android:theme="@android:style/Theme.Black.NoTitleBar" <!-- Then, android:theme must extends Theme.AppCompat -->
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

If you don't need actionBar (NoTitleBar), just change your class to use Activity

public class MainActivity extends Activity { // Instead of extends ActionBarCompat

}

But if you want use ActionBarCompat, so create an custom theme extending Theme.AppCompat

eg.:

public class MyActivityWithActionBarCompat extends ActionBarActivity {


}

/res/values/style.xml

<style name="AppTheme" parent="@style/Theme.AppCompat">
</style>

manifest

<activity
        android:name=".MyActivityWithActionBarCompat"
        android:theme="@style/AppTheme"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

Upvotes: 1

Austyn Mahoney
Austyn Mahoney

Reputation: 11408

You need to use a theme which extends from Theme.AppCompat. This is a requirement when using the AppCompat library.

More info on styling your ActionBar with AppCompat themes here.

Upvotes: 0

Related Questions