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:
into this nicer dialog with elevation
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
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.
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
The Item You Requested Is Not Available for Purchase
How to Programmatically Trigger the Touch Event in Android
Android - Inner Element Must Either Be a Resource Reference or Empty
How to Include Data Files with the App's APK
Preferencefragmentcompat Has Padding on Preferencecategory That I Can't Get Rid Of
Android Ndk: Link Using a Pre-Compiled Static Library
Using Android to Submit to a Google Spreadsheet Form
Getting Started with Open Nfc Emulator
Enabling General JavaScript in Webviewclient
Cannot Resolve Method 'Getsupportfragmentmanager ( )' Inside Fragment
How to Extract the Text from the Selected Item on the Listview
Bitmap Is Returning Null from Bitmapfactory.Decodefile(Filename)
Start a Service in a Separate Process Android
Android: 2 or More Expandablelistview Inside Navigation Drawer
How to Set the Output Image Use Com.Android.Camera.Action.Crop
Generate Barcode Image in Android Application
Glide-4.0.0 Missing Placeholder, Error, Glideapp and Does Not Resolve Its Method Placeholder,Error