Bottom Sheet in android
BottomSheetActivity.class
public class BottomSheetActivity extends AppCompatActivity {
private BottomSheetBehavior mBottomSheetBehavior;
private NestedScrollView mNestedScrollView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bottom_sheet);
mNestedScrollView = (NestedScrollView) findViewById(R.id.activity_coordinate_layout_demo_nsv);
mBottomSheetBehavior = BottomSheetBehavior.from(mNestedScrollView);
}
public void showBottomSheet(View view) {
if (mBottomSheetBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) {
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
} else if(mBottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) {
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
}
}
activity_bottom_sheet.class
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button
style="@style/NormalTextView"
android:text="Show bottom sheet"
android:layout_gravity="center_horizontal"
android:layout_marginTop="25dp"
android:onClick="showBottomSheet"/>
<!-- Nested scroll view can hold one child only-->
<!--Peekhieght make child view to be visible even collapsed-->
<!--setting layout_behavior enable view to be settle at center of total height-->
<android.support.v4.widget.NestedScrollView
android:id="@+id/activity_coordinate_layout_demo_nsv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
app:behavior_peekHeight="50dp"
app:layout_behavior="@string/bottom_sheet_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hellow world"
android:textColor="#ffffff"
android:textSize="65dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hellow world"
android:textColor="#ffffff"
android:textSize="65dp"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
style.xml
<resources><style name="NormalTextView">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">16dp</item>
<item name="android:textColor">@color/colorPrimary</item>
</style></resources>