Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

You need to use a Theme.AppCompat theme (or descendant) with this activity

Android Studio 0.4.5

Android documentation for creating custom dialog boxes: http://developer.android.com/guide/topics/ui/dialogs.html

If you want a custom dialog, you can instead display an Activity as a dialog instead of using the Dialog APIs. Simply create an activity and set its theme to Theme.Holo.Dialog in the <activity> manifest element:

<activity android:theme="@android:style/Theme.Holo.Dialog" > 

However, when I tried this I get the following exception:

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

I am supporting the following, and I can't using something greater than 10 for the min:

minSdkVersion 10 targetSdkVersion 19 

In my styles I have the following:

<!-- Base application theme. -->     <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 

And in my manifest I have this for the activity:

 <application         android:allowBackup="true"         android:icon="@drawable/ic_launcher"         android:label="@string/app_name"         android:theme="@style/AppTheme" >         <activity             android:theme="@android:style/Theme.Holo.Light.Dialog"             android:name="com.ssd.register.Dialog_update"             android:label="@string/title_activity_dialog_update" >         </activity> 

Creating the dialog box like this was something I was hopping to do, as I have already completed the layout.

Can anyone tell me how I can get around this problem?

like image 201
ant2009 Avatar asked Feb 16 '14 17:02

ant2009


People also ask

What is theme AppCompat?

The AppCompat support library provides themes to build apps with the Material Design specification. A theme with a parent of Theme. AppCompat is also required for an Activity to extend AppCompatActivity . The first step is to customize your theme's color palette to automatically colorize your app.

What is the difference between activity and AppCompatActivity?

Activity is the basic one. Based on Activity , FragmentActivity provides the ability to use Fragment . Based on FragmentActivity , AppCompatActivity provides features to ActionBar .


2 Answers

The reason you are having this problem is because the activity you are trying to apply the dialog theme to is extending ActionBarActivity which requires the AppCompat theme to be applied.

Update: Extending AppCompatActivity would also have this problem

In this case, change the Java inheritance from ActionBarActivity to Activity and leave the dialog theme in the manifest as it is, a non Theme.AppCompat value


The general rule is that if you want your code to support older versions of Android, it should have the AppCompat theme and the java code should extend AppCompatActivity. If you have *an activity that doesn't need this support, such as you only care about the latest versions and features of Android, you can apply any theme to it but the java code must extend plain old Activity.


NOTE: When change from AppCompatActivity (or a subclass, ActionBarActivity), to Activity, must also change the various calls with "support" to the corresponding call without "support". So, instead of getSupportFragmentManager, call getFragmentManager.

like image 97
Bobbake4 Avatar answered Sep 19 '22 03:09

Bobbake4


All you need to do is add android:theme="@style/Theme.AppCompat.Light" to your application tag in the AndroidManifest.xml file.

like image 35
iusting Avatar answered Sep 19 '22 03:09

iusting