PopupMenu 使用及自定义样式
Activity引用的XML样式配置 android:theme="@style/AppBaseTheme"
color颜色
#00FFFF
#00FF00
Menu布局
代码实现
/**
* 显示浮动菜单
*/
@SuppressLint("RestrictedApi")
private fun showPopupMenu(view: View) {
val popupMenu = PopupMenu(context!!, vMenu)
getMenuInflater().inflate(R.menu.home_menu, popupMenu.menu)
popupMenu.setOnMenuItemClickListener {
when (it.itemId) {
R.id.vShare -> {
ToastUtils.showLongToast("跳转到分享")
true
}
R.id.vScan -> {
ToastUtils.showLongToast("跳转到扫一扫")
true
}
else -> true
}
}
val menuHelper = MenuPopupHelper(context!!, popupMenu.menu as MenuBuilder, view)
menuHelper.setForceShowIcon(true)//设置显示图标
menuHelper.show()
}