2017-01-29 6 views
2

에 내가 BottomSheetDialogFragment.Everything 완벽 일하고 있어요,하지만 난 하나의 문제 야 내 BottomSheetDialogFragment.This에 PeekHeight를 변경할 수있는 것은 내 소스변경 PeekHeight이 BottomSheetDialogFragment

public class BottomSheet3DialogFragment extends BottomSheetDialogFragment { 

private BottomSheetBehavior mBottomSheetBehavior2; 
private BottomSheetBehavior.BottomSheetCallback 
     mBottomSheetBehaviorCallback = new BottomSheetBehavior.BottomSheetCallback() { 
    @Override 
    public void onStateChanged(@NonNull View bottomSheet, int newState) { 
     if (newState == BottomSheetBehavior.STATE_HIDDEN) { 
      dismiss(); 
     } 
     mBottomSheetBehavior2= BottomSheetBehavior.from(bottomSheet); 
     if(mBottomSheetBehavior2!=null) 
      mBottomSheetBehavior2.setPeekHeight(20); 


    } 

    @Override 
    public void onSlide(@NonNull View bottomSheet, float slideOffset) { 
    } 
}; 

@Override 
public void setupDialog(final Dialog dialog, int style) { 
    super.setupDialog(dialog, style); 
    View contentView = View.inflate(getContext(), R.layout.fragment_bottomsheet3, null); 
    dialog.setContentView(contentView); 
} 

}

mButton3.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      BottomSheet3DialogFragment bottomSheetDialogFragment = new BottomSheet3DialogFragment(); 

      bottomSheetDialogFragment.show(getSupportFragmentManager(), bottomSheetDialogFragment.getTag()); 
     } 
    }); 
입니다

내 조각에서 PeekHeight를 변경할 수 있습니까? 사람이 솔루션은 나에게 감사 dialog.setContentView(contentView);

답변

0

도와주세요 알고 있다면 당신은이를 추가해야한다

dialog.setOnShowListener(new OnShowListener() { 
    @Override 
    public void onShow(DialogInterface dialog) { 
    FrameLayout bottomSheet = dialog.getWindow() 
     .findViewById(android.support.design.R.id.design_bottom_sheet); 
    CoordinatorLayout coordinatorLayout = (CoordinatorLayout) bottomSheet.getParent(); 
    BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet); 
    bottomSheetBehavior.setPeekHeight(bottomSheet.getHeight()); 
    coordinatorLayout.getParent().requestLayout(); 
    } 
}); 

이 코드는 자동으로 높이를 볼 높이를 조정합니다. 고정 된 높이를 원할 경우 bottomSheet.getHeight()을 원하는대로 변경하십시오.