之前没有写过博客,发现好多东西用过都不记得了。
决定从今天开始写博客,增强记忆也方便以后查看。(共勉)
在继承自Activity的activity使用AlertDialog报错: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();
参考自:http://anforen.com/wp/2016/04/alertdialog-java-lang-illegalstateexception-you-need-to-use-a-theme-appcompat-theme-or-descendant-with-this-activity/