Android10 Dialog bug

之前写了个显示电池老化的Dialog,今天发新版本测试的时候报错了。

代码

java 复制代码
		AlertDialog dialog = new AlertDialog.Builder(mContext)
				.setTitle(R.string.battery_aging_dialog_title)
				.setMessage(R.string.battery_aging_dialog_message)
				.setPositiveButton(R.string.ok,null)
				.create();
		dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG);
		dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM|WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
		dialog.setCanceledOnTouchOutside(false);
		dialog.show();

终端表现

黑屏后重新加载界面

报错信息

java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

原因

AlertDialog导入的是androidx包,具体原因未知,有没有大佬知道原因

解决方法

import android.app.AlertDialog就能正常运行了。

相关推荐
癫狂的兔子7 分钟前
【BUG】【Python】逆序取值为空
bug
癫狂的兔子9 分钟前
【BUG】【Python】精确度问题
python·bug
成都大菠萝27 分钟前
2-2-2 快速掌握Kotlin-函数&Lambda
android
成都大菠萝27 分钟前
2-1-1 快速掌握Kotlin-kotlin中变量&语句&表达式
android
癫狂的兔子30 分钟前
【BUG】【Python】合并两个列表
bug
CC.GG35 分钟前
【C++】STL----封装红黑树实现map和set
android·java·c++
renke33641 小时前
Flutter 2025 跨平台工程体系:从 iOS/Android 到 Web/Desktop,构建真正“一次编写,全端运行”的产品
android·flutter·ios
儿歌八万首1 小时前
Android 自定义 View :打造一个跟随滑动的丝滑指示器
android
yueqc12 小时前
Android System Lib 梳理
android·lib