[Android studio] The Alertdialog window is dark.

Asked 1 years ago, Updated 1 years ago, 69 views

Here's the current situation

Java code is

Sagin.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    View dlgView = View.inflate(Activity2.this,ac2_sub,null);
                    AlertDialog.Builder dlg = new AlertDialog.Builder(Activity2.this);
                    ImageView Sagin = (ImageView)dlgView.findViewById(R.id.Sagin);
                    Sagin.setImageResource(foodID[pos]);
                    dlg.setTitle(foodName[pos]);
                    dlg.setIcon(R.drawable.food_bag_small);
                    dlg.setView(dlgView);
                    dlg.setNegativeButton ("Cancel", null);
                    dlg.setPositiveButton("Select", newDialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Intent intent = new Intent(Activity2.this,Activity3.class);
                            startActivity(intent);
                        }
                    });
                    dlg.show();
                }
            });

Like this.

ac2_sub.xml

<LineLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:background="@drawable/custom_background"
    >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/Sagin"/>


</LinearLayout>

This is custom_background.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
    <shape>
        <solid android:color="#ffffff"/>
    </shape>
    </item>
</layer-list>

I want all sides of the dialog to be white

The current suspicion is that all activity action bars have been removed

As a result, activities that darken the background like the picture above

I've processed everything background="#ffffffff"

I don't know what to do with that conversationDe

I don't know where to go.

android-studio java xml dialog

2022-09-22 19:50

1 Answers

AppTheme appears to have the android:alertDialogTheme property.

If you annotate this, it looks like it's going to appear in a white background. Otherwise, there is a way to customize AlertDialog.

//dlg.show();
AlertDialog dialog = dlg.create();
//dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.WHITE));
//or
dialog.getWindow().setBackgroundDrawable(android.R.color.white);
dialog.show();


2022-09-22 19:50

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.