如何结合BottomSheetDialogFragment
主题与其他主题?
我的应用程序具有使用主题制作的皮肤。BottomSheetDialogFragment
应该有圆角,我使用以下方法实现这一点:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.style.CustomBottomSheetDialogTheme) /* hack to make background transparent */
}
Then in 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>
但如果我从Theme.MaterialComponents.Light.BottomSheetDialog
我没有得到我在皮肤主题中定义的配色方案。
那么问题来了:如何在皮肤主题内部定义Dialog主题?
You can add在您的应用程序主题中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>
否则,在您的 BottomSheetDialogFragment 中,您可以覆盖getTheme()
method.
public class RoundedBottomSheetDialog extends BottomSheetDialogFragment {
//....
@Override public int getTheme() {
return R.style.BottomSheetDialog_Rounded;
}
}
另外,为了获得圆角,您可以使用类似的东西:
<!-- 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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)