After switching to version 24.2.1 of the Android Design Support library from version 23.4.0 the BottomSheetBehavior stopped working for me. The BottomSheet shows as open and does not close when calling setState(BottomSheetBehavior.STATE_COLLAPSED)
. This does not happen on 23.4.0 of the Design library where BottomSheetBehaviour works for me as expected.
Did anything change in version 24 that requires using BottomSheetBehavior differently?
Here is my layout file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
android:text="Open Bottom Sheet"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/close_button"
android:text="Close Bottom Sheet"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="horizontal"
android:background="@android:color/holo_green_light"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"/>
And here is the Activity code that I am using:
public class ScrollingActivity extends AppCompatActivity implements View.OnClickListener {
private View m_bottomSheet;
private BottomSheetBehavior m_behaviour;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scrolling);
m_bottomSheet = findViewById(R.id.bottom_sheet);
m_behaviour = BottomSheetBehavior.from(m_bottomSheet);
((Button)findViewById(R.id.button)).setOnClickListener(this);
((Button)findViewById(R.id.close_button)).setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.button:
m_behaviour.setState(BottomSheetBehavior.STATE_EXPANDED);
break;
case R.id.close_button:
m_behaviour.setState(BottomSheetBehavior.STATE_COLLAPSED);
break;
}
}
}
Any advice would be appreciated.
m_behaviour.setPeekHeight(0);
It defaults to the "peek" state, so if you don't want it to peek at all, you need to set the peek height to 0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With