我试图在点击按钮上使用android-support-library 23.2调用BottomSheet.它工作正常,但没有采取全高度.它位于AppBarLayout下方.我在Android Documentation没有找到任何解决方案
这是我的屏幕布局
这是我的代码.
activity_main.xml中
MainActivity.java
View bottomSheet;
private BottomSheetDialog mBottomSheetDialog;
private void initView(){
/*
Bottom Sheet Initialization
*/
CoordinatorLayout coordinatorLayout = (CoordinatorLayout)findViewById(R.id.main_content);
// The View with the BottomSheetBehavior
bottomSheet = coordinatorLayout.findViewById(R.id.bottom_sheet);
behavior = BottomSheetBehavior.from(bottomSheet);
// behavior.setState(BottomSheetBehavior.STATE_HIDDEN);
behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet,int newState) {
// React to state change
CommonMethods.getInstance().e("onStateChanged","onStateChanged:" + newState);
if (newState == BottomSheetBehavior.STATE_EXPANDED) {
fab.setVisibility(View.GONE);
} else {
fab.setVisibility(View.VISIBLE);
}
}
@Override
public void onSlide(@NonNull View bottomSheet,float slideOffset) {
// React to dragging events
CommonMethods.getInstance().e("onSlide","onSlide");
}
});
behavior.setPeekHeight(100);
}
点击事件代码:
@Override
public void onShareClick() {
if (behavior.getState() == BottomSheetBehavior.STATE_EXPANDED) {
behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
if(mBottomSheetDialog==null){
mBottomSheetDialog = new BottomSheetDialog(this);
View view = getLayoutInflater().inflate(R.layout.layout_bottomsheet,null);
mBottomSheetDialog.setContentView(view);
}
mBottomSheetDialog.show();
mBottomSheetDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
mBottomSheetDialog = null;
}
});
}
最佳答案
原文链接:https://www.f2er.com/android/429956.html