为FloatActionButton添加按键点击监听器,在监听器中使用AlertDialog导致程序运行崩溃
logcat输出
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
代码
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//弹窗警告是否删除
new AlertDialog.Builder(getBaseContext())
.setTitle("about&help")
.setMessage("thank you")
.setPositiveButton("ok", null)
.show();
//刷新视图
refresh_list_view();
}
});
问题是new AlertDialog.Builder(getBaseContext())的上下文参数,应该设置成Activity的实例,我是在MainAvtivity中调用的,因此设置成
new AlertDialog.Builder(MainActivity.this)
就可以正常运行