24

有人可以解释一下为什么这个陈述非常有效:

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

并且下一个语句没有传递

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

这就是我在风格部门所拥有的:

<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>
4

5 回答 5

45

尝试使用片段的 onCreate 中的代码作为

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
        
    setStyle(DialogFragment.STYLE_NO_TITLE, R.style.dialog);
}
于 2014-10-27T06:43:34.130 回答
2

https://stackoverflow.com/a/24375599/2898715也可以setStyle完全省略调用,并定义DialogFragments将在整个应用程序中使用的 defulat 样式。

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>
于 2020-03-19T18:43:59.030 回答
1

尝试设置父主题,例如

<style name="dialog" parent="@android:style/Theme.Dialog"> Your theme attributes </style>
于 2013-06-14T17:16:24.337 回答
1

尝试通过如下编程来做到这一点: -

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

或者也可以在 xml 文件中声明。

于 2021-02-11T09:34:18.040 回答
0

从活动中调用bottomSheetDialogFragment:

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.```
于 2021-01-13T05:21:52.503 回答