Can someone please explain why this statement works perfectly well:
setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Holo);
and the next statement does not deliver
setStyle(DialogFragment.STYLE_NO_TITLE, R.style.dialog);
This is what I have in the style's department:
<style name="dialog"> <!-- title encapsulating main part (backgroud) of custom alertdialog --> <item name="android:windowFrame">@null</item> <!-- turn off any drawable used to draw a frame on the window --> <item name="android:windowBackground">@null</item> <!-- turn off any drawable used to draw a frame on the window --> <item name="android:windowIsFloating">true</item> <!-- float the window so it does not fill the screen --> <item name="android:windowNoTitle">true</item> <!-- remove the title bar we make our own--> <item name="android:windowContentOverlay">@null</item> <!-- remove the shadow from under the title bar --> </style>
This class was deprecated in API level 28. Use the Support Library DialogFragment for consistent behavior across all devices and access to Lifecycle.
Show activity on this post. Dialog: A dialog is a small window that prompts the user to make a decision or enter additional information. DialogFragment: A DialogFragment is a special fragment subclass that is designed for creating and hosting dialogs.
This is gonna be disappointing to you "great" finding but just call progressDialog. showDialog() twice back-to-back and you will get two dialogs. Because show is asynchronous and your findFragmentByTag(TAG) == null check will be true until dialog is actually added by system.
Show activity on this post. tl;dr: The correct way to close a DialogFragment is to use dismiss() directly on the DialogFragment. Control of the dialog (deciding when to show, hide, dismiss it) should be done through the API here, not with direct calls on the dialog.
Try using the code in onCreate of the fragment as
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setStyle(DialogFragment.STYLE_NO_TITLE, R.style.dialog); }
https://stackoverflow.com/a/24375599/2898715 it's also possible to omit the setStyle
call altogether, and define the defulat style that DialogFragments
will use throughout the whole app.
styles.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="AppTheme" parent="android:Theme.Holo.Light"> <!-- makes all dialogs in your app use your dialog theme by default --> <item name="alertDialogTheme">@style/DialogTheme</item> <item name="android:alertDialogTheme">?alertDialogTheme</item> <item name="dialogTheme">?alertDialogTheme</item> <item name="android:dialogTheme">?alertDialogTheme</item> </style> <!-- define your dialog theme --> <style name="DialogTheme" parent="Theme.AppCompat.DayNight.Dialog.MinWidth"> <item name="android:buttonStyle">@style/button_green</item> <item name="android:textColorHint">@color/green</item> </style> </resources>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"> ..... <application android:theme="@style/AppTheme"> ..... </application> </manifest>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With