1

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();
    }

}
Alberto Zaccagni
  • 30,779
  • 11
  • 72
  • 106
sider
  • 687
  • 2
  • 9
  • 23

3 Answers3

4

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);
Infinite Recursion
  • 6,511
  • 28
  • 39
  • 51
Sanket Kachhela
  • 10,861
  • 8
  • 50
  • 75
  • See my question http://stackoverflow.com/questions/23196053/set-app-widget-to-home-screen-programmatically – Piyush Apr 24 '14 at 08:55
0

you have to create custom dialog to make changes in background color refer this link

Nambi
  • 11,944
  • 3
  • 37
  • 49
0
<style name="AlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="android:background">@color/myColor</item>
</style>

AlertDialog.Builder builder = new AlertDialog.Builder(Datetimeactivity.this,R.style.AlertDialogTheme);
Makvin
  • 3,475
  • 27
  • 26