-1

In my android application i am showing an alert dialog. I want to change outside color of alert dialog to black color. Please suggest me any one having the idea how can i achieve this. My code for showing alert dialog is:

AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(ctx, R.style.SetdartDialog));
    builder.setView(factory.inflate(R.layout.alert_dialog, null))
    .setIcon(R.drawable.icon)
    .setCancelable(true)
    .setMessage(R.string.check_wireless_settings)
    .setTitle(R.string.no_connection)
    .setPositiveButton(R.string.myes, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            ctx.startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
        }
    })
    .setNegativeButton(R.string.mno, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            return;
        }
    })
    .setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            return;
        }
    })
    .show();

And added the image for reference for my problem.

enter image description here

Raghu Mudem
  • 6,793
  • 13
  • 48
  • 69

2 Answers2

1

Instead of making it black, there is in build Blurring and dimming background windows from dialog's is available in android.

So, here you can make the background Blur

I am using the AlterDialog.Builder to create my dialog, however this method will work with all kinds of dialog providing you can access it via getWindow.

AlertDialog.Builder dialog = new AlertDialog.Builder(WordCube.this)  
    .setTitle(WordCube.this.getResources().getString(R.string.app_name))  
    .setMessage(s)  
    .setIcon(R.drawable.logo)  
    .setPositiveButton(R.string.btn_close, null)  
    .show();  

Below shows the code needed to add blur and remove dimming of the background (as I think the blur looks nicer when the background is well lit).

WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();  
lp.dimAmount=0.0f;  
dialog.getWindow().setAttributes(lp);  
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);

The blur is simply created using the last line (line 4) which sets a flag for the dialog telling android that we want windows below this one to be blurred. To achieve the dimming, we need to retrieve the layout parameters for the dialog window, set the dim amount to zero, update these parameters with setAttributes (lines 1-3).

Any comments, questions, or improvements please let me know.

King of Masses
  • 18,405
  • 4
  • 60
  • 77
0

Before initializing(Showing) the the AlertDialog you can set the visibility of parent layout to INVISIBLE or GONE and before dismissing the AlertDialog make it VISIBLE.

Bhagwat K
  • 2,982
  • 2
  • 23
  • 33
  • Thanks for your replay. In my case i am using preferences for my views not layouts with views. So i can't make it invisible but i can remove all view and add all views. It will effect on performance of my application. – Raghu Mudem Apr 29 '15 at 12:35