public class AreaSelectBottomSheetDialogFragment extends BottomSheetDialogFragment {
private BottomSheetBehavior mBottomSheetBehavior;
private final BottomSheetBehavior.BottomSheetCallback mBottomSheetBehaviorCallback = new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
//禁止拖拽,
if (newState == BottomSheetBehavior.STATE_DRAGGING) {
//设置为收缩状态
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
}
};
@Override
public void onStart() {
super.onStart();
Dialog dialog = getDialog();
mBottomSheetBehavior = BottomSheetBehavior.from(getDialog().findViewById(R.id.design_bottom_sheet));
if (dialog != null) {
View bottomSheet = dialog.findViewById(R.id.design_bottom_sheet);
bottomSheet.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
}
final View view = getView();
view.post(new Runnable() {
@Override
public void run() {
View parent = (View) view.getParent();
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) (parent).getLayoutParams();
CoordinatorLayout.Behavior behavior = params.getBehavior();
mBottomSheetBehavior = (BottomSheetBehavior) behavior;
mBottomSheetBehavior.setBottomSheetCallback(mBottomSheetBehaviorCallback);
Display display = getActivity().getWindowManager().getDefaultDisplay();
//设置高度
int height = display.getHeight() / 2;
mBottomSheetBehavior.setPeekHeight(height);
parent.setBackgroundColor(Color.WHITE);
}
});
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.dialog_fragment_bottom_sheet_area_select, container, false);
init(view);
return view;
}
private void init(View view) {
Display display = getActivity().getWindowManager().getDefaultDisplay();
//设置高度
int height = display.getHeight() / 2;
view.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height));
}
}
代码实现loadingDialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);
ProgressBar progressBar = new ProgressBar(this);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(0,26,0,26);
FrameLayout frameLayout = new FrameLayout(this);
frameLayout.addView(progressBar);
frameLayout.setLayoutParams(layoutParams);
frameLayout.setPadding(0, 46, 0, 46);
builder.setView(frameLayout);
alertDialog = builder.create();
alertDialog.setCancelable(false);
alertDialog.show();