Gần đây, tôi đã sử dụng android.support.design.widget.BottomSheetDialogFragment. Tôi muốn làm một cái gì đó tương tự như ứng dụng liên lạc của Google, BottomSheet của nó có thể che phủ thanh công cụ và thanh trạng thái. Tuy nhiên, khi tôi sử dụng BottomSheetDialogFragment để thực hiện điều này, nó chỉ ra điều này: Làm cho toàn màn hình dướiSheetDialog trên thanh trạng thái
Như bạn có thể thấy thanh công cụ của hoạt động vẫn hiển thị. Đây là mã của tôi về BottomSheetDialogFragment
:
public class KeyDetailFragment extends BottomSheetDialogFragment {
private BottomSheetBehavior.BottomSheetCallback mBottomSheetBehaviorCallback = new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
if (newState == BottomSheetBehavior.STATE_HIDDEN) {
dismiss();
}
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
}
};
@Override
public void setupDialog(Dialog dialog, int style) {
super.setupDialog(dialog, style);
View contentView = View.inflate(getActivity(), R.layout.sheet_key, null);
dialog.setContentView(contentView);
View parent = (View) contentView.getParent();
parent.setFitsSystemWindows(true);
BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(parent);
contentView.measure(0, 0);
bottomSheetBehavior.setPeekHeight(contentView.getMeasuredHeight());
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) parent.getLayoutParams();
if (params.getBehavior() instanceof BottomSheetBehavior) {
((BottomSheetBehavior)params.getBehavior()).setBottomSheetCallback(mBottomSheetBehaviorCallback);
}
params.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
parent.setLayoutParams(params);
}
}
tôi đề cập đến nguồn và tôi thấy một thuộc tính quan tâm tôi:
private static int getThemeResId(Context context, int themeId) {
if (themeId == 0) {
// If the provided theme is 0, then retrieve the dialogTheme from our theme
TypedValue outValue = new TypedValue();
if (context.getTheme().resolveAttribute(
R.attr.bottomSheetDialogTheme, outValue, true)) {
themeId = outValue.resourceId;
} else {
// bottomSheetDialogTheme is not provided; we default to our light theme
themeId = R.style.Theme_Design_Light_BottomSheetDialog;
}
}
return themeId;
}
thuộc tính bottomSheetDialogTheme
đây có thể thay đổi phong cách tấm đáy nhưng tôi không biết cách thay đổi nó, và tôi nghi ngờ liệu điều này có hiệu quả hay không. Ai đó có thể cho tôi giải pháp về việc đạt được nó mà nó có thể che phủ thanh công cụ và thanh trạng thái?
Vấn đề tương tự, bạn có tìm thấy giải pháp nào cho vấn đề này không? –
@ nipun.birla Không, tôi chưa tìm thấy nó mặc dù nó đã trôi qua trong khoảng 3 tháng –
Tôi nghĩ lý do là độ cao. Kiểm tra điều này: http://stackoverflow.com/questions/35711808/android-bottomsheet-is-hinding-under-the-toolbar. –