有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java最近迁移到安卓x,我发现alertdialog存在布局问题

当我将AlertDialog导入与导入安卓x.appcompat.app.AlertDialog一起使用时; 在标题中,我们观察到一个不需要的线性布局

当我改变安卓x.appcompat.app.AlertDialog;到 import 安卓.app.AlertDialog; 问题消失了

import 安卓x.appcompat.app.AlertDialog;


  AlertDialog.Builder builder;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            builder = new AlertDialog.Builder(context, 安卓.R.style.Theme_Material_Dialog_Alert);
        } else {
            builder = new AlertDialog.Builder(context);
        }
builder .setMessage(json)
                    .setTitle("Info")
                    .setIcon(安卓.R.drawable.ic_dialog_alert)
                    .show();

使用安卓x:

Androix import issue

没有但预期:

without 安卓x but expected

提前感谢您的帮助:)


共 (1) 个答案

  1. # 1 楼答案

    这似乎与androidx配合得很好

     new AlertDialog.Builder(this)
                .setTitle(getString(R.string.label_update_available))
                .setMessage(getString(R.string.label_download_content))
                .setPositiveButton(android.R.string.yes, (dialog, which) -> {
                    HandleNotifications.setDownloadReminder(this, DownloadReceiver.class);
                })
                .setNegativeButton(android.R.string.no, (dialog, which) -> dialog.dismiss())
                .show();