我正在使用
BottomSheetDialogFragment
来显示一些数据。但是当我开始 fragment
它出现在屏幕的 50% 时。所以,我的问题是如何在它显示时全屏显示。
BottomSheetDialogFragment
代码:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.bot_frag, container, false);
TextView tv = v.findViewById(R.id.textVi);
back=v.findViewById(R.id.back_of_bot);
back.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
}
);
return v;
}
您可以使用对话框片段,请参考:
public class DialogFragments extends DialogFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
View view = inflater.inflate(R.layout.dialog_dialogfragment_layout, null);
getDialog().setTitle("Title");
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
DisplayMetrics metrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
getDialog().getWindow().setGravity(Gravity.BOTTOM);
getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, (int) (metrics.heightPixels * 0.30));// here i have fragment height 30% of window's height you can set it as per your requirement
getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
getDialog().getWindow().getAttributes().windowAnimations = R.style.DialogAnimationUpDown;
}
当你想打开时,像这样打开 Bottomsheet 对话框:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.bot_frag, container, false);
TextView tv = v.findViewById(R.id.textVi);
back=v.findViewById(R.id.back_of_bot);
back.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentManager fm = getFragmentManager();
DialogFragments dialogFragment = new DialogFragments(this);
dialogFragment.show(fm, "Bottomsheet Fragment");
}
}
);
return v;
}
你必须将这种风格应用到你身上
BottomSheetDialogFragment
android.R.style.Theme_Material_Light_NoActionBar_Fullscreen
此解决方案适用于
BottomSheetDialogFragment
。我还没有测试其他类型的底页视图。你需要做两件事:
container?.minimumHeight = Resources.getSystem().displayMetrics.heightPixels
override fun getTheme(): Int {
return R.style.Theme_Design_BottomSheetDialog
}
第一个动作会将底部工作表高度设置为您的显示器。第二个操作将底部工作表主题设置为填充宽度的主题。现在你有一个全屏底页。