图标和文字同时显示
@SuppressLint("RestrictedApi")
private fun initMenu() {
var menu = toolbar?.getMenu()
if (menu is MenuBuilder) {
//设置图标文字同时显示
menu.setOptionalIconsVisible(true)
}
//设置右边更多按钮(三个点)为黑色
var moreIcon = ContextCompat.getDrawable(this, R.drawable.abc_ic_menu_overflow_material);
if(moreIcon != null) {
moreIcon.setColorFilter(ContextCompat.getColor(this, R.color.color_black), PorterDuff.Mode.SRC_ATOP)
toolbar?.setOverflowIcon(moreIcon)
}
}
menu弹出框遮挡toolbar
<style name="AppOverflowMenuStyle" parent="Base.Widget.AppCompat.Light.PopupMenu.Overflow">
<item name="overlapAnchor">false</item>
<item name="android:popupBackground">@color/white</item>
</style>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="actionOverflowMenuStyle">@style/AppOverflowMenuStyle</item>
</style>