Implement Bottomsheet Of Android Blueprint Back Upward Library

Posted on
BottomSheet run on API 19

BottomSheet run on API 23

With the assistance from the Android Design Support Library, yous tin flaming implement a disclose of of import cloth blueprint components to all developers in addition to to all Android 2.1 or higher devices.

This representative present how to implement Bottom Sheets alongside assistance of Android Design Support Library.


To use Design Support Library inwards your app, yous convey to “Add Android Design Support Library to Android Studio Project“, currently version ‘com.android.support:design:23.4.0’.

activity_main.xml

<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     xmlns:app="http://schemas.android.com/apk/res-auto"     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:context="com.blogspot.android_er.androidbottomsheet.MainActivity">      <LinearLayout         android:id="@+id/backgroundlayout"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:orientation="vertical">         <TextView             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_gravity="center_horizontal"             android:autoLink="web"             android:text="https://rootandroid.org//"             android:textStyle="bold" />         <TextView             android:id="@+id/textSDK"             android:layout_width="match_parent"             android:layout_height="wrap_content" />         <TextView             android:id="@+id/prompt"             android:textSize="28dp"             android:layout_width="match_parent"             android:layout_height="wrap_content" />     </LinearLayout>      <android.support.v4.widget.NestedScrollView         android:id="@+id/bottomsheet"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:clipToPadding="true"         android:background="@android:color/darker_gray"         app:layout_behavior="android.support.design.widget.BottomSheetBehavior">          <LinearLayout             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:orientation="vertical">             <TextView                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_gravity="center_horizontal"                 android:text="Bottom Sheet Example"                 android:textSize="26dp"                 android:textStyle="bold"/>             <ImageView                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:src="@mipmap/ic_launcher"/>         </LinearLayout>      </android.support.v4.widget.NestedScrollView> </android.support.design.widget.CoordinatorLayout>  

MainActivity.java

package com.blogspot.android_er.androidbottomsheet;  import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.design.widget.BottomSheetBehavior; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.LinearLayout; import android.widget.TextView;  world degree MainActivity extends AppCompatActivity {      LinearLayout backgroundLayout;     View bottomSheet;     someone BottomSheetBehavior bottomSheetBehavior;     TextView textPrompt;     TextView textSDK;      /*     Build.VERSION.SDK_INT:     The user-visible SDK version of the framework;     its possible values are defined inwards Build.VERSION_CODES.     https://developer.android.com/reference/android/os/Build.VERSION_CODES.html      */     int sdk_int = Build.VERSION.SDK_INT;      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);          textSDK = (TextView)findViewById(R.id.textSDK);         textSDK.setText("Running SDK_INT: " + sdk_int);          textPrompt = (TextView)findViewById(R.id.prompt);         backgroundLayout = (LinearLayout)findViewById(R.id.backgroundlayout);          bottomSheet = findViewById(R.id.bottomsheet);         bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);         bottomSheetBehavior.setBottomSheetCallback(bottomSheetCallback);          backgroundLayout.setOnClickListener(new View.OnClickListener() {             @Override             world void onClick(View v) {                 switch (bottomSheetBehavior.getState()){                     instance BottomSheetBehavior.STATE_COLLAPSED:                         bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);                         break;                     instance BottomSheetBehavior.STATE_EXPANDED:                         bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);                         break;                 }             }         });      }      BottomSheetBehavior.BottomSheetCallback bottomSheetCallback =             novel BottomSheetBehavior.BottomSheetCallback(){         @Override         world void onStateChanged(@NonNull View bottomSheet, int newState) {             switch (newState){                 instance BottomSheetBehavior.STATE_COLLAPSED:                     textPrompt.setText("COLLAPSED");                     break;                 instance BottomSheetBehavior.STATE_DRAGGING:                     textPrompt.setText("DRAGGING");                     break;                 instance BottomSheetBehavior.STATE_EXPANDED:                     textPrompt.setText("EXPANDED");                     break;                 instance BottomSheetBehavior.STATE_HIDDEN:                     textPrompt.setText("HIDDEN");                     break;                 instance BottomSheetBehavior.STATE_SETTLING:                     textPrompt.setText("SETTLING");                     break;                 default:                     textPrompt.setText("unknown...");             }         }          @Override         world void onSlide(@NonNull View bottomSheet, float slideOffset) {          }     }; }  

(reference:  )

Next:
– Sets the tiptop of collapsed bottom sheet, yesteryear calling setPeekHeight() method
– BottomSheetDialog example


More representative of using Android Design Support Library, Snackbar, FloatingActionButton.