我的警报对话框始终将活动布局更改为白页。使用相机时会弹出对话框。尝试将背景更改为透明,但没有运气。有任何想法吗?附加的模拟器截图。希望使警报对话框在使用相机时出现,而整个屏幕没有白色背景。
代码:
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>
答案 0 :(得分:0)
您忘记将setView
指令添加到警报对话框中。
.setView(R.layout.dialog_layout)
假设您的xml文件名为dialog_layout
,否则将其更改为正确的文件名。
答案 1 :(得分:0)
尝试一下可能会对您有所帮助
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));