【发布时间】:2022-01-19 21:29:20
【问题描述】:
如何让抽屉在 android 中从屏幕顶部显示?
我可以在 material.io 上找到任何关于 in 的消息
此解决方案用于 android chrome 应用程序。
它看起来像这样:
【问题讨论】:
如何让抽屉在 android 中从屏幕顶部显示?
我可以在 material.io 上找到任何关于 in 的消息
此解决方案用于 android chrome 应用程序。
它看起来像这样:
【问题讨论】:
您可以使用自定义视图,因此基本上可以考虑使用 BottomSheetDialogue。使用 16dp 的 bottomLeftRadius 和 bottomRightRadius 为其设置样式。
然后使用 WindowManager 将底部工作表定位在屏幕顶部。这是一种选择。
获取更详细的深入解决方案
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@android:color/white"/>
<corners android:bottomLeftRadius="20dp" android:bottomRightRadius="20dp"/>
</shape>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="bottomSheetDialogTheme">@style/AppBottomSheetDialogTheme</item>
</style>
<style name="AppBottomSheetDialogTheme" parent="Theme.Design.Light.BottomSheetDialog">
<item name="bottomSheetStyle">@style/customCurvedBottomSheet</item>
</style>
<style name="customCurvedBottomSheet" parent="Widget.Design.BottomSheet.Modal">
<item name="android:background">@drawable/rounded_dialogue</item>
<item name="android:paddingBottom">30dp</item>
<item name="android:paddingTop">20dp</item>
</style>
现在您已经为底部工作表创建了一种样式,使其看起来像您想要的那样。
Window window = bottomSheetDialogue.getWindow();
WindowManager.LayoutParams layoutParams = window.getAttributes();
layoutParams.gravity = Gravity.TOP;
layoutParams.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
window.setAttributes(layoutParams);
【讨论】: