【问题标题】:Show an imageview instead of icon on toolbar options menu在工具栏选项菜单上显示图像视图而不是图标
【发布时间】:2020-02-16 14:59:05
【问题描述】:
当您覆盖 onCreateOptionsMenu() 时,您会看到一个选项菜单,当您单击右上角的 3 点图标时会打开该菜单。我想显示一个带有用户图像而不是 3 点图标的圆形图像视图。我该怎么做?
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.options_menu, menu);
return true
}
【问题讨论】:
标签:
android
kotlin
optionmenu
【解决方案1】:
您好@Amol,您可以从codepath guide 了解有关工具栏的更多信息,
尝试替换工具栏
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.AppCompatImageView
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_gravity="end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@mipmap/ic_launcher_round" />
</FrameLayout>
</androidx.appcompat.widget.Toolbar>
如果您只想替换图标并仍然保留溢出菜单
阅读来自this的类似答案