I have a BottomSheet in which there is a RecyclerView to which items are added, how to correctly make the title in this BottomSheet? (as in the picture "add new record") The first thing that comes to mind is to add to the RecyclerView item just with text, but I would like some more elegant solution.

The method in which items are added to RecyclerView:

private void showBottomSheetDialog() { if (behavior.getState() == BottomSheetBehavior.STATE_EXPANDED) { behavior.setState(BottomSheetBehavior.STATE_COLLAPSED); } mBottomSheetDialog = new BottomSheetDialog(this); View view = getLayoutInflater().inflate(R.layout.sheet, null); RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView); recyclerView.setHasFixedSize(true); recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.setAdapter(new ItemAdapter(createItems(), new ItemAdapter.ItemListener() { @Override public void onItemClick(Item item) { if (mBottomSheetDialog != null) { mBottomSheetDialog.dismiss(); } } })); mBottomSheetDialog.setContentView(view); mBottomSheetDialog.show(); mBottomSheetDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { mBottomSheetDialog = null; } }); } @Override protected void onDestroy() { super.onDestroy(); mAdapterItem.setListener(null); } public List<Item> createItems() { ArrayList<Item> items = new ArrayList<>(); items.add(new Item(R.drawable.camera, "from new shoots")); items.add(new Item(R.drawable.folder_multiple_image, "from ready images")); return items; } 

Screen layout:

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.v7.widget.Toolbar android:id="@+id/my_toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#118b0a" android:elevation="4dp" android:theme="@style/ThemeOverlay.AppCompat.ActionBar" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> <android.support.v7.widget.RecyclerView android:id="@+id/list" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/my_toolbar" /> <android.support.design.widget.FloatingActionButton android:id="@+id/float_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:layout_margin="16dp" android:src="@drawable/add_white" /> <android.support.design.widget.CoordinatorLayout android:layout_width="0dp" android:layout_height="0dp"> <LinearLayout android:id="@+id/bottom_sheet" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#fff" android:gravity="center" android:orientation="vertical" app:layout_behavior="@string/bottom_sheet_behavior"> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="16dp" android:layout_marginTop="16dp" android:background="#fff" /> </LinearLayout> </android.support.design.widget.CoordinatorLayout> </RelativeLayout> 

RecyclerView Element in BottomSheet:

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?android:attr/selectableItemBackground" android:clickable="true" android:gravity="center_vertical" android:orientation="horizontal"> <ImageView android:id="@+id/imageView" android:layout_width="40dp" android:layout_height="40dp" android:layout_margin="16dp" android:src="@mipmap/ic_launcher" /> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="16dp" android:layout_marginStart="16dp" android:gravity="center_vertical" android:textColor="#787878" android:textSize="22sp" /> </LinearLayout> 

enter image description here

  • Just add a textview before RecyclerView have not tried? - Yura Ivanov
  • @YuraIvanov Tried, but I have this TextView, not displayed on the screen, you may need to change something in the layout CoordinatorLayout, or LineraLayout, which contains RecyclerView, but I do not know which parameters need to be changed, so that this text is displayed. - Lucky_girl
  • But is it not possible to simply add to the LinearLayout markup, which implements a BottomSheet ( id / bottom_sheet ) TextView with a header, before RecyclerView ? - pavlofff
  • @pavloff I add a TextView in LinearLayout before RecyclerView, but nothing happens, the text does not appear on the screen. - Lucky_girl

1 answer 1

Just today I solved the exact same problem for myself)). Decided to use clickable floating action button (FAB). At the same time, the Add new record entry is represented by the "+" symbol. FAB, when pressed, turns up with two additional buttons, in your case shots and images.

  • I have a FAB with a plus and just such a BottomSheet should appear on it, as in the photo with three inscriptions. - Lucky_girl
  • If you expand FAB as you do, it turns out that the information is “supersaturated”, that the design material is not Camille, it’s enough for the user to reflect the effect of the pictograms. /… - ZigZag
  • if you go, for example, to GoogleDrive, and click on FAB, then BottomSheet appears with a title and GreedView with icons. - Lucky_girl
  • Google Drive, despite the fact that it collected everything under one name, suggests further actions of different types .. i.e. creating a folder, loading (simply “creating”) content, scanning .. i.e. The action is divided into actions of different types. In this case, the bottomsheet application is really justified. In your case, there is a continuation of one action, adding a record, only the source is changing .. so I would still apply the drop-down FAB - ZigZag
  • @ZigZag if the icons are not enough and need a signature, then fab is not the best option. - Yura Ivanov