我正在尝试BottomSheetDialogFragment
建立一个模态底页,但正如您在屏幕截图中看到的那样,它不是在导航栏后面滑动,而是在它的前面。
这是向上滑动的方向。当它完全启动时,它位于导航栏上方。但它出现时看起来很难看。
知道如何解决这个问题吗?
BottomSheet类代码:
public class ExampleBottomSheetDialog extends BottomSheetDialogFragment {
private BottomSheetListener mListener;
public interface BottomSheetListener {
void onButton1Clicked();
void onButton2Clicked();
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
mListener = (BottomSheetListener) context;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.bottom_sheet_layout, container);
Button button1 = v.findViewById(R.id.button1);
Button button2 = v.findViewById(R.id.button2);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mListener.onButton1Clicked();
dismiss();
}
});
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mListener.onButton2Clicked();
dismiss();
}
});
return v;
}
}
在MainActivity
中打开BottomSheet:
Button buttonOpenBottomSheet = findViewById(R.id.button_open_bottom_sheet);
buttonOpenBottomSheet.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ExampleBottomSheetDialog bottomSheet = new ExampleBottomSheetDialog();
bottomSheet.show(getSupportFragmentManager(), "exampleBottomSheet");
}
});