错误: setBadgeCount(this,icon," 0");
这是我的代码:
$h = (int)date('H');
$keys = array('key1','key2','key3','key4');
$key = $keys[floor($h / 6)];
答案 0 :(得分:3)
您得到ClassCastException
,因为MenuItem
不返回BitmapDrawable
,您可以从LayerDrawable
BitmapDrawable
MenuItem
创建BitmapDrawable iconBitmap = (BitmapDrawable) itemCart.getIcon();
LayerDrawable iconLayer = new LayerDrawable(new Drawable [] { iconBitmap });
setBadgeCount(this, iconLayer, "0");
>
根据这个答案(https://stackoverflow.com/a/20138871/4142087)或官方documentation你可以这样做:
float:right
答案 1 :(得分:0)
将可绘制的菜单项图标从可绘制的矢量更改为图层列表。在图层列表中,您可以包括这样的矢量项。这里的购物车图标是矢量。
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/cart_icon"
android:gravity="center" />
<item
android:id="@+id/ic_badge"
android:drawable="@drawable/cart_icon" />
</layer-list>