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
In my case i have no values-v21 file in my res directory. Then i created it and added in it following codes:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
Quick solution.
Change your base theme parent in styles.xml
Replace from
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
to
<style name="AppTheme" parent="Theme.AppCompat">
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.
I had an activity with theme <android:theme="@android:style/Theme.Dialog">
used for showing dialog in my appWidget and i had same problem
i solved this error by changing activity code like below:
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.Theme_AppCompat_Dialog); //this line i added
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dialog);
}
I was getting this same problem. Because i was creating custom navigation drawer. But i forget to mention theme in my manifest like this
android:theme="@style/Theme.AppCompat.NoActionBar"
As soon i added the above the theme to my manifest it resolved the problem.
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
.