android - You need to use a Theme.AppCompat theme (or descendant) with this activity. Change to Theme.AppCompat causes other error

android - You need to use a Theme.AppCompat theme (or descendant) with this activity. Change to Theme.AppCompat causes other error

Margrit Simon Author: Margrit Simon Date: 2022-08-17
android - You need to use a Theme.AppCompat theme (or descendant) with this activity. Change to Theme.AppCompat causes other error

All you need to know about android - You need to use a Theme.AppCompat theme (or descendant) with this activity. Change to Theme.AppCompat causes other error , in addintion to android - How can I fix this error: You need to use a Theme.AppCompat theme (or descendant) with this activity , android - applying splash give me error You need to use a Theme.AppCompat theme (or descendant) with this activity , java - "You need to use a Theme.AppCompat theme (or descendant) with this activity." , android - You need to use a Theme.AppCompat theme (or descendant) with this activity

  1. android - You need to use a Theme.AppCompat theme (or descendant) with this activity. Change to Theme.AppCompat causes other error
  2. Question:

    I use appcompat v22.1.0 in my App and use Toolbar. Everything was fine when I use Theme.AppCompat.Light.NoActionBar. When I start implement AlertDialog, it produce error like this:

    java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
            at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:113)
            at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146)
            at android.support.v7.app.AppCompatDialog.<init>(AppCompatDialog.java:47)
            at android.support.v7.app.AlertDialog.<init>(AlertDialog.java:92)
            at android.support.v7.app.AlertDialog$Builder.create(AlertDialog.java:882)
            at com.ramabmtr.map.findingmoo.MainActivity.onOptionsItemSelected(MainActivity.java:216)
            at android.app.Activity.onMenuItemSelected(Activity.java:2572)
            at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:353)
            at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:144)
            at android.support.v7.internal.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:99)
            at android.support.v7.internal.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:99)
            at android.support.v7.internal.app.ToolbarActionBar$2.onMenuItemClick(ToolbarActionBar.java:74)
            at android.support.v7.widget.Toolbar$1.onMenuItemClick(Toolbar.java:164)
            at android.support.v7.widget.ActionMenuView$MenuBuilderCallback.onMenuItemSelected(ActionMenuView.java:740)
            at android.support.v7.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:802)
            at android.support.v7.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:153)
            at android.support.v7.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:949)
            at android.support.v7.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:939)
            at android.support.v7.widget.ActionMenuView.invokeItem(ActionMenuView.java:598)
            at android.support.v7.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:139)
            at android.view.View.performClick(View.java:4084)
            at android.view.View$PerformClick.run(View.java:16989)
            at android.os.Handler.handleCallback(Handler.java:615)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4812)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:559)
            at dalvik.system.NativeStart.main(Native Method)
    

    Based on that error, I change my theme to Theme.AppCompat and put this:

    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    

    to my theme. But it produce the same error.

    Style.xml (old)

    <resources>
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    </style>
    </resources>
    

    Style.xml (new)

    <resources>
    <style name="AppTheme" parent="Theme.AppCompat">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    </style>
    </resources>
    

    Anyone knows how to fix it??

    MainActivity.java

    package com.ramabmtr.map.findingmoo;
    
    import android.content.DialogInterface;
    import android.graphics.Typeface;
    import android.os.Bundle;
    import android.support.v4.widget.DrawerLayout;
    import android.support.v7.app.ActionBarDrawerToggle;
    import android.support.v7.app.AlertDialog;
    import android.support.v7.app.AppCompatActivity;
    import android.support.v7.widget.RecyclerView;
    import android.support.v7.widget.Toolbar;
    import android.view.View;
    import android.widget.TextView;
    import android.widget.Toast;
    
    public class MainActivity extends AppCompatActivity {
    
    private Toolbar toolbar;
    private TextView toolbarTitle;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayShowTitleEnabled(false);
    
        Typeface myTypeface = Typeface.createFromAsset(getAssets(), "fonts/panpizza.ttf");
        toolbarTitle = (TextView) findViewById(R.id.toolbar_title);
        toolbarTitle.setTypeface(myTypeface);
    
        AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
        builder.setTitle(R.string.filter_title);
        builder.setMessage("test");
        builder.setPositiveButton(R.string.ok_button, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int id) {
                dialog.dismiss();
            }
        });
        builder.setNegativeButton(R.string.cancel_button, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int id) {
                dialog.dismiss();
            }
        });
        AlertDialog dialog = builder.create();
        dialog.show();
    }
    }
    


    Solution 1:

    Fixed my problem by using MainActivity.this (or YourActivityName.this)

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.this);
    

    Make sure you already Theme.AppCompat and extending AppCompatActivity.

    Solution 2:

    Basically your Activity is using Toolbar (which replaces Action Bar) so you need to use style for the Activity that has no Action Bar like Theme.AppCompat.Light.NoActionBar. If you have your own style for dialog then you need to inherit the proper AppCompat theme.

    <style name="myDialog" parent="Theme.AppCompat.Dialog">
        <item name="android:windowNoTitle">true</item>
        ...
    </style>
    

    AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.myDialog));
    

    Solution 3:

    In my case, this crash was caused because I was passing View.getContext().getApplicationContext() as Context to the Builder. This was fixed by using getActivity() instead.

  3. android - How can I fix this error: You need to use a Theme.AppCompat theme (or descendant) with this activity
  4. Question:

    I searched all internet web sites to fix this error, but I couldn't. I just want to create AlertDialog with two button Yes and No.

    This is my code:

    import android.content.DialogInterface;
    import android.support.v7.app.AlertDialog;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    
    public class DialogActivity extends AppCompatActivity {
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dialog);
    
        Button btnDialog= (Button) findViewById(R.id.btnDialog);
        btnDialog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showDialogMessage();
            }
        });
    }
    
    private void showDialogMessage(){
    
        AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
        // Add the buttons
        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                // User clicked OK button
            }
        });
        builder.setNegativeButton("NO", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                // User cancelled the dialog
            }
        });
    
        AlertDialog dialog = builder.create();
        dialog.show();
    }
    }
    

    And this is my Style:

    <resources>
    
    <!-- Base application theme. -->
    <style name="AppTheme" parent="AppTheme.Base">
        <!-- Customize your theme here. -->
    </style>
    
    <style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    

    this is my style(v21):

    <resources>
    <!-- extend one of the Theme.AppCompat themes -->
    <style name="AppTheme" parent="AppTheme.Base">
        <!-- customize the color palette -->
        <item name="android:colorPrimary">@color/colorPrimary</item>
        <item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="android:colorAccent">@color/colorAccent</item>
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:colorControlHighlight">@color/colorHighLight</item>
    </style>
    </resources>
    

    this is manifest:

        <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.saly.rastari" >   
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name=".DialogActivity"
                android:label="@string/title_activity_test"
                android:screenOrientation="portrait" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>       
        </application>
    </manifest>
    

    When I click on Dialog button I get this error:

    11-02 04:36:55.941 24352-24352/? E/AndroidRuntime: FATAL EXCEPTION: main
    11-02 04:36:55.941 24352-24352/? E/AndroidRuntime: Process: com.irannara.pda.pdaassistant, PID: 24352
    11-02 04:36:55.941 24352-24352/? E/AndroidRuntime: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
    11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:309)
    11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:278)
    11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:252)
    11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at android.support.v7.app.AppCompatDialog.setContentView(AppCompatDialog.java:76)
    11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at android.support.v7.app.AlertController.installContent(AlertController.java:216)
    11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at android.support.v7.app.AlertDialog.onCreate(AlertDialog.java:240)
    11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at android.app.Dialog.dispatchOnCreate(Dialog.java:373)
    11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at android.app.Dialog.show(Dialog.java:274)
    11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at com.irannara.pda.pdaassistant.DialogActivity.showDialogMessage(DialogActivity.java:42)
    11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at com.irannara.pda.pdaassistant.DialogActivity.access$000(DialogActivity.java:10)
    11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at com.irannara.pda.pdaassistant.DialogActivity$1.onClick(DialogActivity.java:21)
    11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at android.view.View.performClick(View.java:4780)
    11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at android.view.View$PerformClick.run(View.java:19866)
    11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:739)
    11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:95)
    11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:135)
    11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5254)
    11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
    11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:372)
    11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
    11-02 04:36:55.941 24352-24352/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
    11-02 04:36:55.959 718-718/? E/EGL_emulation: tid 718: eglCreateSyncKHR(1209): error 0x3004 (EGL_BAD_ATTRIBUTE)
    

    none of this links couldn't help me:

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

    • ActionBarCompat: java.lang.IllegalStateException: You need to use a Theme.AppCompat

    • Need to use a Theme.AppCompat theme (or descendant) with this activity???

    and more.

    how can i fix this?


    Solution 1:

    If you have another styles files in side another values folders like "values-v11", "values-v14"... Edit theme also and try to clean your app before running.

    Edited: From your activity change getApplicationContext() to this:

    AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
    

    to

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    

    Because the dialog also should extends the Appcompat Theme.

    Solution 2:

    If anybody experiences this issue with activities, try to explicitly configure a theme to your activity.

    <activity android:name=".activities.BLEControlActivity" android:theme="@style/Theme.AppCompat.DayNight"></activity>
    

    Solution 3:

    You are encountering this error because your AlertDialog is not using AppCompat theme while your activity is. To fix it, use the this property of your activity instead of getApplicationContext(), like so:

    AlertDialog.Builder builder = new AlertDialog.Builder(DialogActivity.this);
    

    The name of your activity, followed by .this, in this case DialogActivity.this, should always be used instead of only this, because if your dialog is created inside another class, for example an adapter of some sort, you will receive a compile-time error stating that a Context was expected instead of the adapter class given.

  5. android - applying splash give me error You need to use a Theme.AppCompat theme (or descendant) with this activity
  6. Question:

    in 23 we have these styles define by default now i have to start splash with full screen

    vlue/stylefile

     <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
            <!-- Customize your theme here. -->
            <item name="colorPrimary">@color/colorPrimary</item>
            <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
            <item name="colorAccent">@color/colorAccent</item>
        </style>
    
        <style name="AppTheme.NoActionBar">
            <item name="windowActionBar">false</item>
            <item name="windowNoTitle">true</item>
        </style>
    
        <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
    
        <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
    

    v21style file:

     <style name="AppTheme.NoActionBar">
            <item name="windowActionBar">false</item>
            <item name="windowNoTitle">true</item>
            <item name="android:windowDrawsSystemBarBackgrounds">true</item>
            <item name="android:statusBarColor">@android:color/transparent</item>
        </style>
    

    manifest:

     android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
            <activity
                android:name=".MainActivity"
                android:label="@string/app_name"
                android:theme="@style/AppTheme.NoActionBar">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity
                android:name=".User_MainInterface"
                android:label="@string/title_activity_user__main_interface"
                android:theme="@style/AppTheme.AppBarOverlay"></activity>
    

    please help me to solve this problem quickly


    Solution 1:

    If you are experiencing this error when implementing the new SplashScreen API for Android 12, don't forget to installSplashScreen:

    SplashScreen splashScreen = SplashScreen.installSplashScreen(this);
    

    Don't forget to add this before setContentView().

    Solution 2:

    If anybody experiences this issue with activities, try to explicitly configure a theme to your activity.

    <activity android:name=".activities.BLEControlActivity" android:theme="@style/Theme.AppCompat.DayNight"></activity>
    

    Solution 3:

    Add this code in your style.xml

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

    then...update your manifest of splash activity like this

    <activity android:name=".MainActivity"
            android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    

  7. java - "You need to use a Theme.AppCompat theme (or descendant) with this activity."
  8. Question:

    I am new to Android programming and I am running into a simple XML issue. I am in the process of trying to make one of my empty activities into a fullscreen activity. I tried adding this line of code android:theme="@android:style/Theme.NoTitleBar.Fullscreen" into my android manifest file, which ended up making my app crash on start.

    If this also helps, my java file for the affected activity extends the AppCompatActivity. I saw some other posts that mentioned that this would create issues but I have not been able to fix my problem.

    Please help me fix this issue while still making the activity fullscreen. Any help is appreciated. Thanks!

    XML

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat.Light">
        <activity android:name=".MainActivity"
            android:label="Marks Calculator">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.APP_CALCULATOR" />
            </intent-filter>
        </activity>
        <activity android:name=".Home_Activity"
            android:label="Finite Time Manager">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.HOME" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Welcome_Activity"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            </activity>
    </application>
    

    Error logcat

    12-22 12:21:30.214 32475-32475/com.managergmail.time.finite.finitemanager02 E/AndroidRuntime: FATAL EXCEPTION: main
        Process: com.managergmail.time.finite.finitemanager02, PID: 32475
        java.lang.RuntimeException: Unable to start activity ComponentInfo{com.managergmail.time.finite.finitemanager02/com.managergmail.time.finite.finitemanager02.Welcome_Activity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2581)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2647)
        at android.app.ActivityThread.-wrap11(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1502)
        at android.os.Handler.dispatchMessage(Handler.java:111)
        at android.os.Looper.loop(Looper.java:207)
        at android.app.ActivityThread.main(ActivityThread.java:5763)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749)
        Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
        at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:359)
        at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:328)
        at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
        at com.managergmail.time.finite.finitemanager02.Welcome_Activity.onCreate(Welcome_Activity.java:17)
        at android.app.Activity.performCreate(Activity.java:6280)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1116)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2534)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2647)
        at android.app.ActivityThread.-wrap11(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1502)
        at android.os.Handler.dispatchMessage(Handler.java:111)
        at android.os.Looper.loop(Looper.java:207)
        at android.app.ActivityThread.main(ActivityThread.java:5763)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749)
    


    Solution 1:

    Your Welcome_Activity probably extends AppCompatActivity so the theme should be appcompat theme.

    In your styles.xml file put this:

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

    Now you can use this theme:

    <activity
        android:name=".Welcome_Activity"
        android:theme="@style/AppTheme.FullScreen">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    

    This will apply fullscreen theme for this particular activity. If you want full screen for whole application you can just replace the application theme in manifest with this theme.

    Solution 2:

    The theme you currently selected (in the welcome activity) isnĀ“t a appcompat theme. This one should for example work: '

    @style/Theme.AppCompat.Light.NoActionBar.FullScreen

  9. android - You need to use a Theme.AppCompat theme (or descendant) with this activity
  10. Question:

    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?


    Solution 1:

    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.

    Solution 2:

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

    Solution 3:

    Copying answer from @MarkKeen in the comments above as I had the same problem.

    I had the error stated at the top of the post and happened after I added an alert dialog. I have all the relevant style information in the manifest. My problem was cured by changing a context reference in the alert builder - I changed:

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

    to:

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

    And no more problems.