0

I don't want to show transparent background when a dialog opens. Can you please suggest an effective way to do that?

Ravindra Kushwaha
  • 7,846
  • 14
  • 53
  • 103
Usman Ishrat
  • 147
  • 1
  • 7
  • Take a loot at this post: http://stackoverflow.com/questions/15007272/how-to-change-the-background-color-around-a-dialogfragment – Rob Feb 03 '16 at 11:29
  • Basically i want to do this "android:backgroundDimEnabled=false " programatically – Usman Ishrat Feb 03 '16 at 11:40

2 Answers2

4

Please check my implementation:

I create a custom dialog with My own layout and added the following code while create the dialog.

dialog = new Dialog(mActivity, R.style.DialogTransparentTheme);
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

My theme under style:

<style name="DialogTransparentTheme" parent="android:Theme">
        <item name="android:textAllCaps">false</item>
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:backgroundDimEnabled">false</item>
        <item name="android:colorControlNormal">@color/app_txt_color</item>
        <item name="android:colorControlActivated">@color/app_txt_gray_color</item>
        <item name="android:colorControlHighlight">@color/app_txt_gray_color</item>
    </style>
Nithinjith
  • 1,775
  • 18
  • 40
0

@Usman This is my custom dialog implementation, and its working fine for me:

View view = mActivity.getLayoutInflater().inflate(R.layout.common_alert_dialog_layout, null);
                TextView titleTextView = (TextView) view.findViewById(R.id.common_alert_dialog_title);
                TextView messageTextView = (TextView) view.findViewById(R.id.common_alert_dialog_message);
                Button okButton = (Button) view.findViewById(R.id.btn_alert_dialog_ok_button);
                titleTextView.setText(getString(R.string.dialog_app_name_header));
                messageTextView.setText(getString(R.string.walk_no_network));
                okButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        dialog.dismiss();
                        // Do your action::
                    }
                });
                dialog.setContentView(view);
                dialog.setCanceledOnTouchOutside(true);
                dialog.setCancelable(true);
                dialog.show();
                dialog.getWindow().setLayout((int) getResources().getDimension(R.dimen.common_dialog_width),
                        (int) getResources().getDimension(R.dimen.common_diaog_height));

                return dialog;

Append the above code to this dialog.

Nithinjith
  • 1,775
  • 18
  • 40
  • Thnaks, but when i use the theme like this "dialog = new Dialog(mActivity, R.style.DialogTransparentTheme);" then it is not cancelling on side click – Usman Ishrat Feb 04 '16 at 05:08
  • Refer the link http://stackoverflow.com/questions/8384067/how-to-dismiss-the-dialog-with-click-on-outside-of-the-dialog – Nithinjith Feb 04 '16 at 09:06