gpt4 book ai didi

不占用整个宽度的Android BottomSheetDialogFragment

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:20:54 26 4
gpt4 key购买 nike

如何制作不覆盖整个屏幕宽度的 BottomSheetDialogFragment(类似于平板电脑上 Chrome 中的“共享方式”工作表)?

最佳答案

正如开发人员在@UfoXp 链接的问题中所建议的那样,问题是 BottomSheetDialog.onCreate() 将窗口设置为 MATCH_PARENT 两种方式:

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Dialog dialog = super.onCreateDialog(savedInstanceState);

if ((isTablet(getContext()) || isLandscape(getContext()))) {
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialogINterface) {
dialog.getWindow().setLayout(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.MATCH_PARENT);
}
});
}
return dialog;
}

private boolean isTablet(Context context) {
return (context.getResources().getConfiguration().screenLayout
& Configuration.SCREENLAYOUT_SIZE_MASK)
>= Configuration.SCREENLAYOUT_SIZE_LARGE;
}

private boolean isLandscape(Context context) {
return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
}

关于不占用整个宽度的Android BottomSheetDialogFragment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37549452/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com