Advertisement
Guest User

Untitled

a guest
Jun 24th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.72 KB | None | 0 0
  1. private void showBottomSheetDialog() {
  2. if (behavior.getState() == BottomSheetBehavior.STATE_EXPANDED) {
  3. behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
  4. }
  5.  
  6. mBottomSheetDialog = new BottomSheetDialog(this);
  7.  
  8.  
  9. View view = getLayoutInflater().inflate(R.layout.sheet, null);
  10. RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
  11. recyclerView.setHasFixedSize(true);
  12. recyclerView.setLayoutManager(new LinearLayoutManager(this));
  13. recyclerView.setAdapter(new ItemAdapter(createItems(), new ItemAdapter.ItemListener() {
  14. @Override
  15. public void onItemClick(Item item) {
  16. if (mBottomSheetDialog != null) {
  17. mBottomSheetDialog.dismiss();
  18. }
  19. }
  20. }));
  21.  
  22. mBottomSheetDialog.setContentView(view);
  23. mBottomSheetDialog.show();
  24. mBottomSheetDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
  25. @Override
  26. public void onDismiss(DialogInterface dialog) {
  27. mBottomSheetDialog = null;
  28. }
  29. });
  30. }
  31.  
  32.  
  33. @Override
  34. protected void onDestroy() {
  35. super.onDestroy();
  36. mAdapterItem.setListener(null);
  37. }
  38.  
  39. public List<Item> createItems() {
  40. ArrayList<Item> items = new ArrayList<>();
  41. items.add(new Item(R.drawable.camera, "from new shoots"));
  42. items.add(new Item(R.drawable.folder_multiple_image, "from ready images"));
  43. return items;
  44. }
  45.  
  46. <?xml version="1.0" encoding="utf-8"?>
  47. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  48. xmlns:app="http://schemas.android.com/apk/res-auto"
  49. android:layout_width="match_parent"
  50. android:layout_height="match_parent"
  51. android:orientation="vertical">
  52.  
  53. <android.support.v7.widget.Toolbar
  54. android:id="@+id/my_toolbar"
  55. android:layout_width="match_parent"
  56. android:layout_height="wrap_content"
  57. android:background="#118b0a"
  58. android:elevation="4dp"
  59. android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
  60. app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
  61.  
  62. <android.support.v7.widget.RecyclerView
  63. android:id="@+id/list"
  64. android:layout_width="match_parent"
  65. android:layout_height="wrap_content"
  66. android:layout_below="@+id/my_toolbar" />
  67.  
  68. <android.support.design.widget.FloatingActionButton
  69. android:id="@+id/float_button"
  70. android:layout_width="wrap_content"
  71. android:layout_height="wrap_content"
  72. android:layout_alignParentBottom="true"
  73. android:layout_alignParentEnd="true"
  74. android:layout_alignParentRight="true"
  75. android:layout_margin="16dp"
  76. android:src="@drawable/add_white" />
  77.  
  78.  
  79. <android.support.design.widget.CoordinatorLayout
  80. android:layout_width="0dp"
  81. android:layout_height="0dp">
  82.  
  83.  
  84. <LinearLayout
  85. android:id="@+id/bottom_sheet"
  86. android:layout_width="match_parent"
  87. android:layout_height="wrap_content"
  88. android:background="#fff"
  89. android:gravity="center"
  90. android:orientation="vertical"
  91. app:layout_behavior="@string/bottom_sheet_behavior">
  92.  
  93. <android.support.v7.widget.RecyclerView
  94. android:id="@+id/recyclerView"
  95. android:layout_width="match_parent"
  96. android:layout_height="wrap_content"
  97. android:layout_marginBottom="16dp"
  98. android:layout_marginTop="16dp"
  99. android:background="#fff" />
  100.  
  101. </LinearLayout>
  102.  
  103. </android.support.design.widget.CoordinatorLayout>
  104.  
  105. </RelativeLayout>
  106.  
  107. <?xml version="1.0" encoding="utf-8"?>
  108. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  109. android:layout_width="match_parent"
  110. android:layout_height="wrap_content"
  111. android:background="?android:attr/selectableItemBackground"
  112. android:clickable="true"
  113. android:gravity="center_vertical"
  114. android:orientation="horizontal">
  115.  
  116. <ImageView
  117. android:id="@+id/imageView"
  118. android:layout_width="40dp"
  119. android:layout_height="40dp"
  120. android:layout_margin="16dp"
  121. android:src="@mipmap/ic_launcher" />
  122.  
  123. <TextView
  124. android:id="@+id/textView"
  125. android:layout_width="wrap_content"
  126. android:layout_height="wrap_content"
  127. android:layout_marginLeft="16dp"
  128. android:layout_marginStart="16dp"
  129. android:gravity="center_vertical"
  130. android:textColor="#787878"
  131. android:textSize="22sp" />
  132.  
  133. </LinearLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement