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就能正常运行了。

相关推荐
Jerry1 天前
Compose 的阶段
android
Zhangzy@1 天前
Rust 编译优化选项
android·开发语言·rust
某空m1 天前
【Android】View滑动的实现
android
芝麻开门-新起点1 天前
Android 和 iOS 系统版本及开发适配
android·ios·cocoa
2501_915918411 天前
iOS描述文件功能解析
android·macos·ios·小程序·uni-app·cocoa·iphone
用户69371750013841 天前
一文彻底搞懂 Android 依赖配置:implementation vs testImplementation,再也不混淆!
android
-雷阵雨-1 天前
软件测试全解析:Bug生命周期与争议解决
bug
南林yan1 天前
Bug: 升级内核后有线网络无法使用
bug
月巴月巴白勺合鸟月半1 天前
一个DevExpress的Docx文件处理的Bug的解决
c#·bug
ao_lang1 天前
软件测试-BUG篇
bug