How to change AlertDialog view background color?

sider

I want to know how could I change that grey color on my alert dialog? I have tried that:

layout.setBackgroundResource(R.color.Aqua);

It didn't work. Any ideas?

My AlertDialog

I have created AlertDialog with the following code:

public class CustomInputDialog{

    private OnDialogClickListener listener;
    private Context context;
    private String title;
    private String message;
    EditText input;
    LinearLayout layout;

    public interface OnDialogClickListener {
        void onDialogOKClick(String value);
    }

    public CustomInputDialog(String title, String message, Context context, OnDialogClickListener listener) {

        super();
        this.title = title;
        this.message = message;
        this.context = context;
        this.listener = listener;

        layout = new LinearLayout(context);
        layout.setOrientation(LinearLayout.VERTICAL);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        params.setMargins(20, 10, 20, 10);

        input = new EditText(context);

        InputFilter[] filters = new InputFilter[1];
        filters[0] = new InputFilter.LengthFilter(20);
        input.setFilters(filters);

        layout.addView(input, params);

    }

    private void dialog(){

        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setCancelable(true);
        builder.setView(layout);
        builder.setTitle(title);
        builder.setMessage(message); 
        builder.setInverseBackgroundForced(true);
        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
                String value = input.getText().toString();
                listener.onDialogOKClick(value);
                dialog.dismiss();
          }
        });
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
              }
        });
        AlertDialog alert = builder.create();
        alert.show();
    }

}
Sanket Kachhela

you can set custom view programmatically like this way..

LayoutInflater inflater = getLayoutInflater();
View dialoglayout = inflater.inflate(R.layout.dialog_layout, (ViewGroup) getCurrentFocus());
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(dialoglayout);
builder.show();

then after to get reference of component

e.g. Button btn = (Button) dialoglayout.findViewById(R.id.button_id);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how can I change the background color of the header using an alertDialog in flutter?

How to change the default background color of AlertDialog from translucent to transparent

How to use animatorSet to change background color of a View

Change background color for the action section in Flutter alertDialog

How to change the color of an AlertDialog message?

How to change background/color of the drawable set as background of a view?

Android: How can I change AlertDialog Title Text Color and Background Color without using custom layout?

Background color not change TextEditor view

How to change the background color

How to change the background color of a view from a different activity in android?

How to get and change drawable background color in custom view

How to change background view color partialy in ios swift

How to change UIWindow background color through a view controller

How to change Background Color of a View containing a List back to White in SwiftUI

iOS Swift - How to change background color of Table View?

How to change the background color of selected expandable table view cell

How to change the background color of tree-view in kivy python?

android how to change background colour in AlertDialog

How to change button text color in AlertDialog

How to set background color of a View

Change the background of the AlertDialog

SwiftUI: how to make List view transparent? How to change List view background color?

Change background color of a view without removing drawable

Animate change of view background color on Android

Change Recycler view item background color by code

Unable to change background color of view in SwiftUI

change background color of view by its ID in Titanium

Change the background color of a Navigation View in Swift 5

How can I change the color of AlertDialog title and the color of the line under it