底板的隐藏状态

时间:2017-02-09 16:06:58

标签: android bottom-sheet

我正在尝试为BottomSheet设置隐藏状态,但它不起作用。问题是什么?

 bottomBar = BottomSheetBehavior.from(findViewById(R.id.bottom_bar));
 bottomBar.setState(BottomSheetBehavior.STATE_HIDDEN);

8 个答案:

答案 0 :(得分:24)

请记住在活动/片段

的开头隐藏底部工作表时添​​加此项
bottomSheetBehavior =BottomSheetBehavior.from(bottom_sheet_view_here);
bottomSheetBehavior.setHideable(true);//Important to add
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);

答案 1 :(得分:4)

mBottomSheetBehaviour.setPeekHeight(0);

使用它,它会隐藏。

答案 2 :(得分:3)

尝试以下方法:

LinearLayout bottomSheetViewgroup  
= (LinearLayout) findViewById(R.id.bottom_sheet);

BottomSheetBehavior bottomSheetBehavior =  
BottomSheetBehavior.from(bottomSheetViewgroup);

然后使用

bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);

答案 3 :(得分:1)

确保在Activity的生命周期中不要过早地执行此操作。如果您需要在onCreate或类似内容中进行此操作,请尝试将其放入您发布到视图的Runnable中,如下所示:

getWindow().getDecorView().post(new Runnable() {
    @Override
    public void run() {
        bottomBar = BottomSheetBehavior.from(findViewById(R.id.bottom_bar));
        bottomBar.setState(BottomSheetBehavior.STATE_HIDDEN);
    }
 });

这不是最干净的解决方案,但它有时是不可避免的。

答案 4 :(得分:1)

 bottomsheetbehavior.setPeekHeight(0, true);

用小动画隐藏:)

            bottomSheet.animate()
                    .translationYBy(bottomSheetBehavior.getPeekHeight());

答案 5 :(得分:0)

尝试BottomSheetBehaviour.STATE_COLLAPSED

bottomBar = BottomSheetBehavior.from(findViewById(R.id.bottom_bar));
bottomBar.setState(BottomSheetBehavior.STATE_COLLAPSED);

答案 6 :(得分:0)

如果你使用像Tabbed Activity这样的东西,你可以隐藏你的片段中的bottomsheetlayout。

我认为这是可能的,因为片段视图是在活动视图之后创建的。

class "activity"
   public void hideBottomSheet(){ 
      sheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
   }

class "fragment"
   onCreateView()
      ((YourActivity.class)getActivity()).hideBottomSheet();

答案 7 :(得分:0)

另一种方式 - 这样你就不需要import configparser

Fragments
相关问题