Как изменить высоту фрагмента диалогового окна нижнего листа по умолчанию?

При использовании фрагмента диалога нижнего листа он устанавливает высоту по умолчанию для диалогового окна нижнего листа. В моем приложении я хочу установить 80% высоты диалогового окна нижнего листа. Как я могу установить 80% высоты диалогового окна нижнего листа?


person Community    schedule 03.10.2017    source источник
comment
показать свою работу.   -  person IntelliJ Amiya    schedule 03.10.2017


Ответы (2)


Попробуйте следующий код.

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();
person Community    schedule 03.10.2017

вы можете сделать это, это работает, замените 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>
person Nouh Mohamed    schedule 11.08.2020