• Register
0 votes
93 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

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 15 views
15 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 Raphael Pacheco 4.9k points
0 votes
2 answers 500 views
500 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 jwilliam 3.9k points
0 votes
1 answer 6 views
6 views
Problem: I am new to Android. I have recently encountered the below error in my Android. Missing styles. Is the correct theme chosen for this layout? Use the Theme combo box above the layout to choose a different layout, or fix the theme style references. Failed ... have also chosen the Google Apis build target as well. Now can somebody here be available to guide me in my Android related error?
asked Aug 31 Raphael Pacheco 4.9k points
0 votes
1 answer 55 views
55 views
Problem : In my current application I want to get the MS-Word and PDF files through the Storage Access Framework which works well on some of the devices I have worked upon however on the Samsung note 4 API 6 I am facing following error : All apps ... "application/pdf,application/msword"); Intent i = Intent.createChooser(intent, "File"); getActivity().startActivityForResult(i, FILE_REQ_CODE); } });
asked Dec 6, 2019 alecxe 7.5k points