使用AlertDialog报错 You need to use a Theme.AppCompat theme (or descendant) with this activity.之解决
2017-09-29 13:41
1066 查看
以前由于继承自ActionBarActivity用得好好的,现在直接继承Activity,使用AlertDialog,则会报以下这个错误:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
可以这样解决,在styles.xml中
添加
<style name=”AlertDialogCustom” parent=”Theme.AppCompat.Light.Dialog.Alert”>
<item name=”android:background”>#FFFFFF</item>
</style>
然后在代码中,这样处理
AlertDialog.Builder builder = new AlertDialog.Builder(
AcceptanceListActivity.this,
R.style.AlertDialogCustom);
builder.setTitle(“我是标题”);
builder.setMessage(“我是内容”);
builder.setPositiveButton(“确定”,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
}
});
builder.show();
OK,解决了。
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
可以这样解决,在styles.xml中
添加
<style name=”AlertDialogCustom” parent=”Theme.AppCompat.Light.Dialog.Alert”>
<item name=”android:background”>#FFFFFF</item>
</style>
然后在代码中,这样处理
AlertDialog.Builder builder = new AlertDialog.Builder(
AcceptanceListActivity.this,
R.style.AlertDialogCustom);
builder.setTitle(“我是标题”);
builder.setMessage(“我是内容”);
builder.setPositiveButton(“确定”,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
}
});
builder.show();
OK,解决了。
相关文章推荐
- 使用AlertDialog报错 You need to use a Theme.AppCompat theme (or descendant) with this activity.之解决
- 使用ActionBar,调整Theme时遇到You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
- You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
- You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
- You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
- 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.
- You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
- Activity使用主题不兼容报错-You need to use a Theme.AppCompat theme (or descendant) with this activity
- you need to use a theme.appcompat theme (or descendant) with this activity 解决办法
- You need to use a Theme.AppCompat theme (or descendant) with this activity解决
- 报错:You need to use a Theme.AppCompat theme (or descendant) with this activity.
- 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.
- You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
- You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
- You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
- Android解决在清单文件里消除Bar报错:You need to use a 原来Theme.AppCompat theme (or descendant) with this activity.
- You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
- You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法