【问题标题】:How to change the default height of bottomsheet dialog fragment?如何更改底页对话框片段的默认高度?
【发布时间】:2017-10-03 18:47:07
【问题描述】:

在使用底页对话框片段时,它为底页对话框设置默认高度。在我的应用程序中,我想为底页对话框设置 80% 的高度。如何将 80% 的高度设置为底页对话框?

【问题讨论】:

  • 展示你的作品。

标签: android bottom-sheet


【解决方案1】:

试试下面的代码。

super.setupDialog(dialog, style);

View contentView = View.inflate(getContext(), R.layout.activity_device_nfclocation, null);

DisplayMetrics displayMetrics = getActivity().getResources().getDisplayMetrics();

int width = displayMetrics.widthPixels;
int height = displayMetrics.heightPixels;

int maxHeight = (int) (height*0.88);

BottomSheetBehavior mBehavior = BottomSheetBehavior.from((View) contentView.getParent());
mBehavior.setPeekHeight(maxHeight);
dialog.show();

【讨论】:

    【解决方案2】:

    你可以这样做,它可以用你需要的任何高度替换 600dp

    <style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
       
        
        <item name="bottomSheetDialogTheme">@style/CustomBottomSheet</item>
        
    </style>
    
    
    <style name="CustomBottomSheet" 
        parent="Theme.MaterialComponents.Light.BottomSheetDialog">
             <item name="bottomSheetStyle">@style/AppModalStyle</item>
    </style>
    
    <style name="AppModalStyle" parent="Widget.Design.BottomSheet.Modal">
    
        <item name="behavior_peekHeight">600dp</item>
    </style>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多