androidx.appcompat.app.AlertDialog始终从活动布局更改为白色背景

问题描述 投票:0回答:2

我的警报对话框始终将活动布局更改为白页。使用相机时会弹出对话框。尝试将背景更改为透明,但没有运气。有任何想法吗?附加的模拟器截图。希望在使用相机时显示警报对话框,而整个屏幕没有白色背景。

代码:

  AlertDialog alertDialog = new AlertDialog.Builder(this)
                //set icon
                .setIcon(android.R.drawable.ic_dialog_alert)
                //set title
                .setTitle("Kan ikke finne produktet i databasen")
                //set message
                .setMessage("Vil du søke manuelt?")
                // Background
                //set positive button
                .setPositiveButton("Ja", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Intent intent = new Intent(ScanActivity.this, ManualActivity.class);
                        startActivity(intent);
                    }
                })
                //set negative button
                .setNegativeButton("Nei", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Intent intent = new Intent(ScanActivity.this, ScanActivity.class);
                        startActivity(intent);                        }
                })

                .show();

XML

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:app="http://schemas.android.com/apk/res-auto">

    <com.journeyapps.barcodescanner.BarcodeView
        android:id="@+id/zxing_barcode_surface"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        app:zxing_framing_rect_width="225dp"
        app:zxing_framing_rect_height="275dp"
        />

    <com.journeyapps.barcodescanner.ViewfinderView
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:id="@+id/zxing_viewfinder_view"
        app:zxing_possible_result_points="#FFC300"
        app:zxing_viewfinder_laser="#EA1818"
        app:zxing_result_view="#2DA818"
        app:zxing_viewfinder_mask="@color/zxing_custom_viewfinder_mask"
        />

    <TextView
        android:id="@+id/zxing_status_view"
        android:layout_width="wrap_content"
        android:layout_height="25dp"
        android:layout_gravity="bottom|center_horizontal"
        android:background="@color/zxing_transparent"
        android:text="@string/barcode_help"
        android:textColor="@color/zxing_status_text"
        />

</merge>

Screenshot from emulator

android android-camera android-alertdialog zxing
2个回答
0
投票

您忘了在警报对话框中添加setView指令。

.setView(R.layout.dialog_layout)

假定您的xml文件名为dialog_layout,否则将其更改为正确的名称。


0
投票

尝试一下可能会对您有所帮助

alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
© www.soinside.com 2019 - 2024. All rights reserved.