如何禁用BottomSheetDialogFragment手指拖动?
我看到了类似的问题,但它们都是关于BottomSheet而不是BottomSheetDialogFragment.
最佳答案创建MyActivity如下: public class MyActivity extends AppCompatActivity { @OverrIDe protected voID onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_my); new MyBottomSheetFragment().show(getSupportFragmentManager(),"tag"); } public static class MyBottomSheetFragment extends BottomSheetDialogFragment { @OverrIDe public Dialog onCreateDialog(Bundle savedInstanceState) { BottomSheetDialog bottomSheetDialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState); bottomSheetDialog.setContentVIEw(R.layout.sample); try { FIEld mBehaviorFIEld = bottomSheetDialog.getClass().getDeclaredFIEld("mBehavior"); mBehaviorFIEld.setAccessible(true); final BottomSheetBehavior behavior = (BottomSheetBehavior) mBehaviorFIEld.get(bottomSheetDialog); behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { @OverrIDe public voID onStateChanged(@NonNull VIEw bottomSheet,int newState) { if (newState == BottomSheetBehavior.STATE_DRAGGING) { behavior.setState(BottomSheetBehavior.STATE_EXPANDED); } } @OverrIDe public voID onSlIDe(@NonNull VIEw bottomSheet,float slIDeOffset) { } }); } catch (NoSuchFIEldException e) { e.printstacktrace(); } catch (illegalaccessexception e) { e.printstacktrace(); } return bottomSheetDialog; } } }
R.layout.sample是一个简单的布局:
你会得到以下输出:
解决方案的一部分是从this答案中借来的. 总结
以上是内存溢出为你收集整理的android – 如何禁用BottomSheetDialogFragment拖动全部内容,希望文章能够帮你解决android – 如何禁用BottomSheetDialogFragment拖动所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)