作为标题,我想在BottomNavigationView的MenuItem上显示徽章计数。我已经搜索了几种方法,但没有人为我工作。
请指点我解决这个问题。我会感激任何帮助。
答案 0 :(得分:0)
BottomNavigationView 是 FrameLayout 。将一个 TextView 放在BottomNavigationView中进行计数:
<android.support.design.widget.BottomNavigationView android:id="@id/bottomMenu" style="@style/bottomMenu">
<TextView android:id="@id/bottomMenuSelectionsNumber" style="@style/bottomMenuSelectionsNumber"/>
</android.support.design.widget.BottomNavigationView>
并按照这样设计:
<style name="bottomMenu">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">@dimen/toolbarHeight</item>
<item name="android:layout_gravity">center|bottom</item>
<item name="android:background">@color/colorThird</item>
<item name="itemBackground">@drawable/tabs_ripple</item>
<item name="itemIconTint">@drawable/bottom_menu_item_color</item>
<item name="itemTextColor">@drawable/bottom_menu_item_color</item>
<item name="menu">@menu/bottom_menu</item>
</style>
<style name="bottomMenuSelectionsNumber">
<item name="android:text">@string/bottomMenuSelectionsNumber</item>
<item name="android:textSize">@dimen/appSecondFontSize</item>
<item name="android:textColor">@color/white</item>
<item name="android:layout_width">@dimen/bottomMenuSelectionsNumberDim</item>
<item name="android:layout_height">@dimen/bottomMenuSelectionsNumberDim</item>
<item name="android:layout_gravity">right|bottom</item>
<item name="android:layout_marginRight">@dimen/bottomMenuSelectionsNumberMarginR</item>
<item name="android:layout_marginBottom">@dimen/bottomMenuSelectionsNumberMarginB</item>
<item name="android:gravity">center</item>
<item name="android:includeFontPadding">false</item>
<item name="android:background">@drawable/bottom_menu_selections_number_bg</item>
</style>
bottom_menu_selections_number_bg :
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<solid android:color="@color/colorAccent"/>
<corners android:radius="@dimen/cornerRadius"/>
</shape>
答案 1 :(得分:-1)
答案 2 :(得分:-1)
创建了示例项目并在GITHub中共享,希望这有助于
https://github.com/chandrahasan/BadgeView-Android/
badgeIcon = (View) findViewById(R.id.badgeIcon);
initBadge(this);
private void initBadge(Context paramContext) {
this.badgeCount = new BadgeView(paramContext);
this.badgeCount.setTargetView(this.badgeIcon);
this.badgeCount.setBadgeCount(count);
this.badgeCount.setBadgeMargin(9);
}