Dialogfragment with Clear Background (Not Dimmed)

DialogFragment with clear background (not dimmed)

What works for me is to adjust the WinowManager.LayoutParams in onStart() of the DialogFragment:

@Override public void onStart() {
super.onStart();

Window window = getDialog().getWindow();
WindowManager.LayoutParams windowParams = window.getAttributes();
windowParams.dimAmount = 0.90f;
windowParams.flags |= WindowManager.LayoutParams.FLAG_DIM_BEHIND;
window.setAttributes(windowParams);
}

Dim background of DialogFragment on Android 4.4.4 (KitKat)

I was not able to fix the dim issue on Android 4.4.4. The best result that I got was from this dialog:

Sample Image

into this nicer dialog with elevation

Sample Image

To do this, simply use this import of the DialogFragment:

import android.app.DialogFragment;

Finally, of course, use the proper FragmentManager:

FragmentManager fm = getFragmentManager();

Cheers!

Can't make the custom DialogFragment transparent over the Fragment

Try

getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

in your DialogFragment's onCreateView

How do I make a Dialog Fragment's background invisible?

You can design the layout like following. There is an extra layout, but in case of dialogs, it will help

Sample Image

Why is a portion of the screen not been covered by the default transparency of the DialogFragment?

Well, the solution was forgetting about everything, taking a bath, some pills and going to sleep.

Also some important tips:

  • Optimizing Imports to clear any extra imports.
  • ".txt" everything that is not needed.
  • Comment everything that's not needed.
  • Clearing AS caches + restart,
  • Uninstalling everything from all devices.
  • Clearing the testing DB (Just in case).
  • Rebooting all devices.

That seemed to be the solution.

How can I change default black dim background color (not the amount of dim) of Dialog?

This is a workaround but it's not really a pure solution because background touch is disabled and should be configured manually.

First, set custom dialog theme like this.

styles.xml

<style name="CustomDialogTheme" parent="android:Theme.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>

Setting windowIsFloating to false forces Dialog view to be expanded to full screen. Setting windowBackground to transparent removes default black dim background under Dialog. windowNoTitle option gets rid of the upper title bar.

CustomDialog.java

Apply the theme and construct your custom_dialog view as follows.

public HTCustomDialog(Context context) {
super(context, R.style.CustomDialogTheme);
setContentView(R.layout.custom_dialog);
}

custom_dialog.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/main_solid_80">

<RelativeLayout
android:id="@+id/dialog_root"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:background="@drawable/bg_popup"
android:padding="16dp">

</RelativeLayout>

Now that CustomDialog view is a full-screen view, set background of your root layout to whatever color you'd like.

Sample result

I mosaiced the result a bit.

Result

remove white background in dialogfragment

In the onCreateView() of your DialogFragment, replace

View rootView = inflater.inflate(R.layout.dialog_select_account, container, false);

with

View rootView = inflater.inflate(R.layout.dialog_select_account, container);

Also, add this to onViewCreated():

getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
setStyle(DialogFragment.STYLE_NO_FRAME, android.R.style.Theme);

and in the outermost LinearLayout of the XML, change

android:layout_width="fill_parent"
android:layout_height="fill_parent"

to

android:layout_height="wrap_content"
android:layout_width="wrap_content"

Try this. This should work.



Related Topics



Leave a reply



Submit