我试图禁用用户拖动BottomSheet.我想禁用的原因是两件事.1.它阻止ListView向下滚动,2.我不希望用户使用拖动但是使用按钮来解除BottomSheetView.这就是我所做的
bottomSheetBehavior = BottomSheetBehavior.from(bottomAnc);
bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
if (newState == BottomSheetBehavior.STATE_EXPANDED) {
//Log.e("BottomSheet", "Expanded");
} else if (newState == BottomSheetBehavior.STATE_COLLAPSED) {
//Log.e("BottomSheet", "Collapsed");
}
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
// React to dragging events
bottomSheet.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = MotionEventCompat.getActionMasked(event);
switch (action) {
case MotionEvent.ACTION_DOWN:
return false;
default:
return true;
} …Run Code Online (Sandbox Code Playgroud) LinearLayout bottomSheetViewgroup = (LinearLayout) findViewById(R.id.bottomSheet);
bottomSheetBehavior = BottomSheetBehavior.from(bottomSheetViewgroup);
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); //this line
Run Code Online (Sandbox Code Playgroud)
我在我的activity的onCreate()方法中有这个代码,当执行最后一行时,我得到了下面的NPE异常:
引发者:java.lang.NullPointerException:尝试在android.support.design.widget.BottomSheetBehavior.setState上的空对象引用上调用虚方法'java.lang.Object java.lang.ref.WeakReference.get()'( BottomSheetBehavior.java:440)
android nullpointerexception android-appcompat material-design
如何禁用BottomSheetDialogFragment手指拖动?
我看到了类似的问题,但他们BottomSheet都不是BottomSheetDialogFragment.
android android-layout android-view android-dialog bottom-sheet