You can use the bottom sheets. I put some info about this.
Using the Android 23.2 Support Library, Google announced support for Bottom Sheets. According to Material Design, bottom sheets are elements that are displayed only as a result of a user-initiated action to reveal more content.
There are two main types of bottom sheets:
Modal bottom sheets are alternatives to menus or simple dialogs. They can also present deeply related content from other applications. They are mainly for mobile devices.
Permanent bottom sheets represent in-app content
There is a simple example.
Making BottomSheet on Android is pretty simple, you just need to use the CoordinatorLayout as the main layout element and attach the BottomSheet behavior to the view.
1 step - 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:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffffff"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/AppTheme.AppBarOverlay"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" /> </android.support.design.widget.AppBarLayout> <Button android:id="@+id/btnButtonSheet" android:text="Camera" android:textColor="#1e1e1e" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" android:layout_marginBottom="8dp" android:layout_width="match_parent" android:layout_height="wrap_content" /> <include layout="@layout/bottom_sheet" /> </android.support.design.widget.CoordinatorLayout>
2 steps - add bottom_sheet.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/bottom_sheet" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#fff" android:orientation="vertical" app:behavior_hideable="true" app:behavior_peekHeight="0dp" app:layout_behavior="android.support.design.widget.BottomSheetBehavior"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_gravity="center_vertical"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Select your options!" android:gravity="center" android:textColor="#1e1e1e" android:textSize="16dp" android:layout_margin="8dp" android:textStyle="bold" /> </LinearLayout> <Button android:id="@+id/btnPhoto" android:text="Photo" android:textColor="#1e1e1e" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" android:layout_marginBottom="8dp" android:layout_width="match_parent" android:layout_height="wrap_content" /> <Button android:id="@+id/btnCamera" android:text="Camera" android:textColor="#1e1e1e" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" android:layout_marginBottom="8dp" android:layout_width="match_parent" android:layout_height="wrap_content" /> <Button android:id="@+id/btnCancel" android:text="Cancel" android:background="#a2a2a3" android:textColor="#1e1e1e" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" android:layout_marginBottom="8dp" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout>
3 steps - configure your MainActivity as follows:
public class MainActivity extends AppCompatActivity { @BindView(R.id.btnButtonSheet) Button btnBottomSheet; @BindView(R.id.bottom_sheet) LinearLayout layoutBottomSheet; BottomSheetBehavior sheetBehavior; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); sheetBehavior = BottomSheetBehavior.from(layoutBottomSheet); sheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { @Override public void onStateChanged(@NonNull View bottomSheet, int newState) { switch (newState) { case BottomSheetBehavior.STATE_HIDDEN: break; case BottomSheetBehavior.STATE_EXPANDED: { btnBottomSheet.setText("Close"); } break; case BottomSheetBehavior.STATE_COLLAPSED: { btnBottomSheet.setText("Expand"); } break; case BottomSheetBehavior.STATE_DRAGGING: break; case BottomSheetBehavior.STATE_SETTLING: break; } } @Override public void onSlide(@NonNull View bottomSheet, float slideOffset) { } }); } @OnClick(R.id.btnButtonSheet) public void toggleBottomSheet() { if (sheetBehavior.getState() != BottomSheetBehavior.STATE_EXPANDED) { sheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); btnBottomSheet.setText("Close Bottom sheet"); } else { sheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); btnBottomSheet.setText("Expand Bottom sheet"); } } }
Faxriddin Abdullayev Feb 07 '18 at 12:21 2018-02-07 12:21
source share