I am trying to show icons in BottomSheeet but only text shows. I read lot of threads on SO but none of them seem to help or are old.
Seeking help on latest android version. Appreciate any help.
List<MenuItem> bottomSheetMenuItems = new ArrayList<>(optionsList.size());
Drawable drawable = getResources().getDrawable(android.R.drawable.ic_dialog_email,
getContext().getTheme());
MenuItem bottomSheetMenuItem = new BottomSheetMenuItem(
getContext(),
someId,
"Test",
drawable);
bottomSheetMenuItem.setChecked(true).setChecked(true);
bottomSheetMenuItems.add(bottomSheetMenuItem);
BottomSheet bottomSheet = new BottomSheet
.Builder(getContext())
.setTitle("Test Title")
.setMenuItems(bottomSheetMenuItems)
.create();
bottomSheet.show();
For icons, you would have to create an xml for bottomsheet.
XML example
<LinearLayout app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
android:id="@+id/intervalBottomSheet"
android:layout_width="match_parent"
android:layout_height="400dp"
android:orientation="vertical"
android:background="?attr/colorPrimary"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ImageView
android:src="@drawable/ic_remove_red_eye_black_24dp" />
<TextView
android:text="MenuItem" />
Java code
final BottomSheetDialog mBottomSheetDialog = new BottomSheetDialog(getActivity());
View sheetView = getActivity().getLayoutInflater().inflate(R.layout.bottomsheet_interval, null);
mBottomSheetDialog.setContentView(sheetView);
mBottomSheetDialog.show();
If your menu items are dynamic and not constant, you could use a recyclerview in the bottomsheetdialog.
With that in mind, you'll need to do this to load the icons
ImageView img= (ImageView) findViewById(R.id.image);
img.setImageResource(R.drawable.my_image);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.