Android:BottomSheetMenuItem不';在菜单中不显示图标

Android:BottomSheetMenuItem不';在菜单中不显示图标,android,bottom-sheet,Android,Bottom Sheet,我试图在Bottomsheet中显示图标,但只显示文本。我读了很多关于SO的文章,但没有一篇是有用的,也没有一篇是旧的 正在寻求有关最新android版本的帮助。谢谢你的帮助 List<MenuItem> bottomSheetMenuItems = new ArrayList<>(optionsList.size()); Drawable drawable = getResources().getDrawable(android.R.drawable.ic_dialog

我试图在Bottomsheet中显示图标,但只显示文本。我读了很多关于SO的文章,但没有一篇是有用的,也没有一篇是旧的

正在寻求有关最新android版本的帮助。谢谢你的帮助

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();
List bottomSheetMenuItems=newarraylist(optionsList.size());
Drawable Drawable=getResources().getDrawable(android.R.Drawable.ic\u对话框\u电子邮件,
getContext().getTheme());
MenuItem bottomSheetMenuItem=新的bottomSheetMenuItem(
getContext(),
有人,
“测试”,
可牵引);
bottomSheetMenuItem.setChecked(真)。setChecked(真);
添加(bottomSheetMenuItem);
底板底板=新底板
.Builder(getContext())
.setTitle(“测试标题”)
.setMenuItems(底部表单MenuItems)
.create();
show();

对于图标,您必须为底部工作表创建一个xml

XML示例

<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" />
如果您的菜单项是动态的而不是恒定的,您可以在bottomsheetdialog中使用recyclerview

考虑到这一点,您需要这样做来加载图标

ImageView img= (ImageView) findViewById(R.id.image);
img.setImageResource(R.drawable.my_image);
ImageView img= (ImageView) findViewById(R.id.image);
img.setImageResource(R.drawable.my_image);