android - java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity -
i trying use alert dialog on delete button. showing exception show dialog. when click on delete crashes , shows exception on .show.
i tried use theme.appcompat theme activity still crashes.
<activity android:name=".addeventactivity" android:theme="@style/theme.appcompat"> </activity> delete.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { new alertdialog.builder(getapplicationcontext()) .settitle("delete entry") .setmessage("are sure want delete entry?") .setpositivebutton(android.r.string.yes, new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int which) { toast.maketext(getapplicationcontext(), "yaay", toast.length_short).show(); = new intent(); db.deleteevent(eventdata); log.i("d", "delete"); setresult(result_ok, i); finish(); // continue delete } }) .setnegativebutton(android.r.string.no, new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int which) { // nothing } }) .seticon(android.r.drawable.ic_dialog_alert) .show(); } });
my theme
<!-- base application theme. --> <style name="apptheme" parent="theme.appcompat.light.noactionbar"> <!-- customize theme here. --> <item name="colorprimary">@color/colorprimary</item> <item name="colorprimarydark">@color/colorprimarydark</item> <item name="coloraccent">@color/coloraccent</item> <item name="windowactionbaroverlay">false</item> <item name="windowactionbar">false</item> <item name="windownotitle">true</item> <item name="android:windowbackground">@color/background_material_light</item> </style> <style name="apptheme.appbaroverlay" parent="themeoverlay.appcompat.dark.actionbar" /> <style name="apptheme.popupoverlay" parent="themeoverlay.appcompat.light" /> </resources>
thank you.
u using wrong context have use activity context , not application context
change:
new alertdialog.builder(getapplicationcontext())
to
new alertdialog.builder(youractivityname.this)
Comments
Post a Comment