之前写了个显示电池老化的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就能正常运行了。