您的位置:首页 > 移动开发

使用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,解决了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐