How to set the theme for DialogFragment

后端 未结 4 1761
暖寄归人
暖寄归人 2021-02-07 02:22

Can someone please explain why this statement works perfectly well:

setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Holo);

and th

相关标签:
4条回答
  • 2021-02-07 03:05

    Its probably too late to answer but try using the code in onCreate of the fragment as

    @Override
        public void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
    
            setStyle(DialogFragment.STYLE_NO_TITLE, R.style.dialog);
        }
    
    0 讨论(0)
  • 2021-02-07 03:07

    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.```
    
    0 讨论(0)
  • 2021-02-07 03:08

    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>
    
    0 讨论(0)
  • 2021-02-07 03:16

    Try setting a parent theme like

    <style name="dialog" parent="@android:style/Theme.Dialog"> Your theme attributes </style>
    
    0 讨论(0)
提交回复
热议问题