Android How to implement Bottom Sheet from Material Design docs
Answering my own question so developers know that the new support library provides this finally! All hail the all powerful Google!
An example from the Android Developer's Blog:
// The View with the BottomSheetBehavior
View bottomSheet = coordinatorLayout.findViewById(R.id.bottom_sheet);
BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);
behavior.setBottomSheetCallback(new BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
// React to state change
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
// React to dragging events
}
});
@reVerse's answer above is still a valid option but its nice to know that there is a standard that Google supports too.
How to implement Bottom Sheets using new design support library 23.2
use layout like below
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout>
<android.support.design.widget.CollapsingToolbarLayout>
<ImageView/>
<android.support.v7.widget.Toolbar/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout>
//.....
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<FrameLayout
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:behavior_hideable="true"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
//your bottom sheet layout
</LinearLayout>
</FrameLayout>
<android.support.design.widget.FloatingActionButton/>
</android.support.design.widget.CoordinatorLayout>
in Activity
CoordinatorLayout coordinatorLayout = (CoordinatorLayout) findViewById(R.id.main_content);
// The View with the BottomSheetBehavior
View bottomSheet = coordinatorLayout.findViewById(R.id.bottom_sheet);
final BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);
behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
// React to state change
Log.e("onStateChanged", "onStateChanged:" + newState);
if (newState == BottomSheetBehavior.STATE_EXPANDED) {
fab.setVisibility(View.GONE);
} else {
fab.setVisibility(View.VISIBLE);
}
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
// React to dragging events
Log.e("onSlide", "onSlide");
}
});
behavior.setPeekHeight(100);
Material Design how Google Maps
For the sliding up scroll you can use the SlidingUpPanel by umano.
GitHub
Related Topics
Using Camera in the Android Emulator
Run Task Before Compilation Using Android Gradle Plugin
How to Open My Existing Eclipse Projects in Android Studio
Programmatically Add View One Below Other in Relative Layout
Pagination Not Work for the Recyclerview Within Nestedscrollview
Continuous Speech Recognition Android
How to Set Alarm in Android Programmatically
Suppress/Block Broadcastreceiver in Another App
Android: Fragments Overlapping Issue
Downloading/Caching Google Maps for Offline Use
Image Share Intent Works for Gmail But Crashes Fb and Twitter
How to Add Android Support V7 Libraries in Eclipse
How to Default to Numeric Keyboard on Edittext Without Forcing Numeric Input
Listen to Own Application Uninstall Event on Android
How to Disable Status Bar Click and Pull Down in Android
How to Get My Location Changed Event with Google Maps Android API V2