24

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>
Graham Borland
  • 60,055
  • 21
  • 138
  • 179
PageMaker
  • 395
  • 1
  • 3
  • 10

5 Answers5

45

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);
}
Cristan
  • 12,083
  • 7
  • 65
  • 69
idle_developer
  • 556
  • 5
  • 8
4

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>
Eric
  • 16,397
  • 8
  • 68
  • 76
1

Try setting a parent theme like

<style name="dialog" parent="@android:style/Theme.Dialog"> Your theme attributes </style>
Sagar Kacha
  • 8,338
  • 4
  • 18
  • 27
user1634451
  • 5,133
  • 6
  • 30
  • 43
  • @blackbelt: I'm noy allowed to place pictures so it's a bit hard to explain in words. – PageMaker Jun 15 '13 at 09:55
  • I tried that; but no change. The direct use of Theme_Holo gives me the expected dark background without a title; just what I want. The use of my own style "dialog" presents me with a dialog box that I don't want. – PageMaker Jun 15 '13 at 09:59
1

Try doing so through programming like below:-

setStyle(DialogFragment.STYLE_NO_TITLE, R.style.dialog);

or can be declared in xml file as well.

Kuldeep Rathee
  • 282
  • 2
  • 7
0

Calling the bottomSheetDialogFragment from the activty:

var bottomFragment = ServiceOtpVerficationFragment()
bottomFragment.setStyle(BottomSheetDialogFragment.STYLE_NO_TITLE,R.style.BottomSheetTheme)
bottomFragment.show(supportFragmentManager,"TAG")
Add this in styles.xml
    
    <style name="BottomSheetTheme" parent="Theme.Design.Light.BottomSheetDialog">        <item name="bottomSheetStyle">@style/BottomSheetStyle</item>
    </style>
    <style name="BottomSheetStyle" parent="Widget.Design.BottomSheet.Modal">        
    <item name="android:background">@android:color/transparent</item>

And In the fragment add extension as `BottomSheetDialogFragment()` to fragment class using colon.```