• Register
0 votes
715 views

Problem :

I wanted to create a custom dialog by displaying the Activity as the dialog instead of using a Dialog APIs. By creating an activity and seting its theme to the Theme.Holo.Dialog in my <activity> manifest element:

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

But  when I tried it I get a below exception:

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

I want to support the following, and I am unable to use something greater than 10 for the min:

minSdkVersion 10
targetSdkVersion 19

In my styles I have the below code :

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

And in my manifest I have below code 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 a dialog box like this was something I wanted to do, because I have already completed my layout.

Can somebody tell me how I can resolve this problem?

7 5 2
3,870 points

Please log in or register to answer this question.

2 Answers

0 votes

Solution :

The reason behind your problem is as a activity you are trying to apply a dialog theme to is extending ActionBarActivity which always requires a AppCompat theme to be applied.

Just extending AppCompatActivity would also have above problem

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

This will solve your issue.

9 7 4
38,600 points
0 votes

Solution:

The base you are having this problem is cause the activity you are attempting to apply the dialog theme to is extending ActionBarActivity which needs the AppCompat theme to be applied.

Update: 

Extending AppCompatActivity would even have this issue

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

The general rule is that in case you want your code to backing older versions of Android, it must have the AppCompat theme and the java code must extend AppCompatActivity. In case you have *an activity that doesn't require this support, such as you just care about the latest versions and features of Android, you can utilize any theme to it however the java code should extend plain old Activity.

NOTE: 

At the time alter from AppCompatActivity (or a subclass, ActionBarActivity), to Activity, should also alter the several calls with "support" to the similar call without "support". Hence, instead of getSupportFragmentManager, call getFragmentManager.

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

I had the error explained at the top of the post and occured after I included an alert dialog. I have all the pertinent style information in the manifest. My problem was solved by altering a context reference in the alert builder - I altered:

new android.support.v7.app.AlertDialog.Builder(getApplicationContext())

to:

new android.support.v7.app.AlertDialog.Builder(this)

min sdk is 10. ActionBar is available from api level 11. So for 10 you would be employing AppCompat from the support library for which you require to employ Theme.AppCompat or descendant of the same.

Use

android:theme="@style/Theme.AppCompat" >

Or in case you dont want action bar at the top

android:theme="@style/Theme.AppCompat.NoActionBar">

Your application has an AppCompat theme

<application
    android:theme="@style/AppTheme">

However, you overwrote the Activity (which extends AppCompatActivity) with a theme that isn't descendant of an AppCompat theme

<activity android:name=".MainActivity"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >

You could identify your own fullscreen theme like so (notice AppCompat in the parent=)

<style name="AppFullScreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

Then fixed that on the Activity.

<activity android:name=".MainActivity"
    android:theme="@style/AppFullScreenTheme" >

 

10 6 4
31,120 points

Related questions

0 votes
1 answer 3 views
3 views
Problem: 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. ... " > </activity> Creating the dialog box like this was something I was hoping to do, as I have already completed the layout.
asked Apr 27 Jack20 5.1k points
0 votes
1 answer 55 views
55 views
Problem: I have the latest version of android studio (3.0) along with the latest build tools (27) and also have the similar API level. But my layout does not get rendered in my design tab and because of this it is causing the lot of trouble especially while ... workable fix for the above problem. I have already spent more than three days on this issue. Is there any work around for this problem?
asked Jul 28, 2020 Raphael Pacheco 4.9k points
1 vote
1 answer 2 views
2 views
Problem : Any solution to this issue > No resource found that matches the given name '@style/Theme.AppCompat.Light'
asked 6 days ago Abik Dey 4k points
0 votes
1 answer 1 view
1 view
Problem: I need someone&rsquo;s help to fix it .. How to make navigation drawer in android
asked 4 days ago Ifra 34.7k points
0 votes
1 answer 8 views
8 views
Problem: Please help me to solve it ... Android resize imageview based on screen size
asked Mar 26 Ifra 34.7k points
0 votes
1 answer 10 views
10 views
Problem: Please solve it &hellip; Because I am unable to find out the solution... float c = cos(angle);
asked Mar 24 Ifra 34.7k points
0 votes
1 answer 2 views
2 views
Problem: I want to gain information on $(window).
asked Apr 13 zayed1 58.7k points
0 votes
2 answers 1.2K views
1.2K views
Problem : I want to upload the finished android app to a android market but I am getting below error: &ldquo;You need to use a different package name because "com.example" is restricted.&rdquo;
asked Jan 22, 2020 jwilliam 3.9k points
0 votes
1 answer 13 views
13 views
Problem: Can anyone tell me how can I declare an activity in your androidmanifest.xml?
asked Apr 1 zayed1 58.7k points