【问题标题】:how to implement android drawe that slides from top of main activity?如何实现从主要活动顶部滑动的android drawe?
【发布时间】:2022-01-19 21:29:20
【问题描述】:

如何让抽屉在 android 中从屏幕顶部显示?
我可以在 material.io 上找到任何关于 in 的消息

此解决方案用于 android chrome 应用程序。
它看起来像这样:

https://imgur.com/a/BBPkxd4

第二步:
https://imgur.com/LnSopsv

【问题讨论】:

    标签: java android xml


    【解决方案1】:

    您可以使用自定义视图,因此基本上可以考虑使用 BottomSheetDialogue。使用 16dp 的 bottomLeftRadius 和 bottomRightRadius 为其设置样式。

    然后使用 WindowManager 将底部工作表定位在屏幕顶部。这是一种选择。

    获取更详细的深入解决方案

    1. 创建具有圆角的可绘制形状
    <?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>
    
    1. 在您的styles.xml 文件中。继续输入这个
      <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>
    
    

    现在您已经为底部工作表创建了一种样式,使其看起来像您想要的那样。

    1. 在实现底部工作表之后,继续使用 WindowManager 将其定位到顶部。
    Window window = bottomSheetDialogue.getWindow();
    WindowManager.LayoutParams layoutParams = window.getAttributes();
    
    layoutParams.gravity = Gravity.TOP;
    layoutParams.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
    window.setAttributes(layoutParams);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-11
      • 1970-01-01
      • 2014-04-10
      相关资源
      最近更新 更多