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

前端 未结 30 3983
感动是毒
感动是毒 2020-11-21 04:42

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 d

相关标签:
30条回答
  • 2020-11-21 04:53

    I had the same problem, but it solved when i put this on manifest: android:theme="@style/Theme.AppCompat.

        <application
            android:allowBackup="true"
            android:icon="@drawable/icon"
            android:label="@string/app_name_test"
            android:supportsRtl="true"
            android:theme="@style/Theme.AppCompat">
    
            ...    
    
        </application>
    
    0 讨论(0)
  • In my experiences the problem was the context where I showed my dialog. Inside a button click I instantiate an AlertDialog in this way:

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

    But the context was not correct and caused the error. I've changed it using the application context in this way:

    In declare section:

    Context mContext;
    

    in the onCreate method

    mContext = this;
    

    And finally in the code where I need the AlertDialog:

    start_stop = (Button) findViewById(R.id.start_stop);
    start_stop.setOnClickListener( new View.OnClickListener()
         {
                    @Override
                    public void onClick(View v)
                    {
                        if (!is_running)
                        {
                            builder = new AlertDialog.Builder(mContext);
                            builder.setMessage("MYTEXT")
                                    .setCancelable(false)
                                    .setPositiveButton("SI", new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog, int id) {
                                        Task_Started = false;
                                        startTask();
                                        }
                                    })
                                    .setNegativeButton("NO",
                                            new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog, int id) {
                                            dialog.cancel();
                                        }
                                    });
                            AlertDialog alert = builder.create();
                            alert.show();
                        }
                }
            }
    

    This is the solution for me.

    0 讨论(0)
  • 2020-11-21 04:53

    Your Activity is extending ActionBarActivity which requires the AppCompat.theme to be applied. Change from ActionBarActivity to Activity or FragmentActivity, it will solve the problem.

    If you use no Action bar then :

    android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" 
    
    0 讨论(0)
  • 2020-11-21 04:54

    You have many solutions to that error.

    1. You should use Activity or FragmentActivity instead of ActionbarActivity or AppCompatActivity

    2. If you want use ActionbarActivity or AppCompatActivity, you should change in styles.xml Theme.Holo.xxxx to Theme.AppCompat.Light (if necessary add to DarkActionbar)

    If you don't need advanced attributes about action bar or AppCompat you don't need to use Actionbar or AppCompat.

    0 讨论(0)
  • 2020-11-21 04:54

    This solution worked for me.

    Design library depends on the Support v4 and AppCompat Support Libraries, so don't use different version for appcompat and design library in gradle.

    use

     compile 'com.android.support:appcompat-v7:23.0.0'
     compile 'com.android.support:design:23.0.0'
    

    instead of

     compile 'com.android.support:appcompat-v7:23.0.0'
     compile 'com.android.support:design:23.1.0'
    
    0 讨论(0)
  • 2020-11-21 04:57

    go to your styles and put the parent

    parent="Theme.AppCompat"
    

    instead of

    parent="@android:style/Theme.Holo.Light"
    
    0 讨论(0)
提交回复
热议问题