Android 带蒙皮的BottomSheetDialogFragment主题

Android 带蒙皮的BottomSheetDialogFragment主题,android,android-theme,bottom-sheet,material-components,material-components-android,Android,Android Theme,Bottom Sheet,Material Components,Material Components Android,如何将blottomSheetDialogFragment主题与其他主题相结合 我的应用程序有使用主题制作的皮肤BottomSheetDialogFragment应该有圆角,我使用以下方法实现这一点: override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.s

如何将
blottomSheetDialogFragment
主题与其他主题相结合

我的应用程序有使用主题制作的皮肤
BottomSheetDialogFragment
应该有圆角,我使用以下方法实现这一点:

 override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.style.CustomBottomSheetDialogTheme) /* hack to make background transparent */
 }
然后在
styles.xml
中:

<style name="CustomBottomSheetStyle" parent="Widget.Design.BottomSheet.Modal">
    <item name="android:background">@android:color/transparent</item>
</style>

<style name="CustomBottomSheetDialogTheme" parent="Theme.MaterialComponents.Light.BottomSheetDialog">
    <item name="bottomSheetStyle">@style/CustomBottomSheetStyle</item>
</style>

@android:彩色/透明
@样式/自定义样式
但是如果我从
主题.MaterialComponents.Light.BottomSheetDialog扩展,我就不会得到我在皮肤主题中定义的颜色方案

所以问题是:如何在皮肤主题中定义对话框主题?

覆盖FunonCreateDialog(@Nullable savedInstanceState:Bundle?):Dialog
override fun onCreateDialog(@Nullable savedInstanceState: Bundle?): Dialog 
val dialog = BottomSheetDialog(context!!,R.style.FullScreenBottomSheet)

<style name="FullScreenBottomSheet" 
parent="Theme.MaterialComponents.Light.BottomSheetDialog">
<item name="android:windowFullscreen">false</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowBackground">@color/transparent</item>
<item name="android:statusBarColor">@color/transparent</item>
</style>
val dialog=BottomSheetDialog(context!!,R.style.FullScreenBottomSheet) 假的 @空的 @彩色/透明 @彩色/透明
试试这个

kotlin

override fun getTheme(): Int = R.style.CustomBottomSheetDialogTheme
java

@Override
public int getTheme() {
     return R.style.CustomBottomSheetDialogTheme
}

您可以在应用程序主题中添加
bottomSheetDialogTheme
属性,以便在应用程序中全局设置bottomsheetDialog样式

<style name="AppTheme" parent="Theme.MaterialComponents.*">
   ......
   <item name="bottomSheetDialogTheme">@style/BottomSheetDialog_Rounded</item>
</style>

<style name="BottomSheetDialog_Rounded" parent="@style/ThemeOverlay.MaterialComponents.BottomSheetDialog">
    <item name="bottomSheetStyle">@style/BottomSheet_Rounded</item>
</style>
此外,为了获得圆角,您可以使用以下方法:

  <!-- BottomSheet Dialog-->
  <style name="BottomSheetDialog_Rounded" parent="@style/ThemeOverlay.MaterialComponents.BottomSheetDialog">
    <item name="bottomSheetStyle">@style/BottomSheet_Rounded</item>
  </style>

  <style name="BottomSheet_Rounded" parent="Widget.MaterialComponents.BottomSheet">
    <item name="shapeAppearanceOverlay">@style/ShapeAppearanceBottomSheetDialog_Rounded</item>
  </style>

  <style name="ShapeAppearanceBottomSheetDialog_Rounded" parent="">
    <item name="cornerFamily">rounded</item>
    <item name="cornerSizeTopRight">16dp</item>
    <item name="cornerSizeTopLeft">16dp</item>
    <item name="cornerSizeBottomRight">0dp</item>
    <item name="cornerSizeBottomLeft">0dp</item>
  </style>

@样式/底页_圆角
@样式/形状PearanceBottomSheetDialog\u圆角
圆的
16dp
16dp
0dp
0dp

您是否在“setupDialog”覆盖方法中的BottomSheetDialogFragment中设置了任何视图?当然,我会膨胀XML。实际上,我是在onCreateView中完成的。最后,我将颜色从主题复制粘贴到对话框主题。似乎是唯一的解决办法:/
  <!-- BottomSheet Dialog-->
  <style name="BottomSheetDialog_Rounded" parent="@style/ThemeOverlay.MaterialComponents.BottomSheetDialog">
    <item name="bottomSheetStyle">@style/BottomSheet_Rounded</item>
  </style>

  <style name="BottomSheet_Rounded" parent="Widget.MaterialComponents.BottomSheet">
    <item name="shapeAppearanceOverlay">@style/ShapeAppearanceBottomSheetDialog_Rounded</item>
  </style>

  <style name="ShapeAppearanceBottomSheetDialog_Rounded" parent="">
    <item name="cornerFamily">rounded</item>
    <item name="cornerSizeTopRight">16dp</item>
    <item name="cornerSizeTopLeft">16dp</item>
    <item name="cornerSizeBottomRight">0dp</item>
    <item name="cornerSizeBottomLeft">0dp</item>
  </style>