Search code examples
androidandroid-alertdialogandroid-popupwindow

Don't show transparent screen on background of custom Dialog in Android


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


Solution

  • 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>