Custom item in the BottomNavigationView

2019-07-23 13:42发布

I would like to create a BottomNavigationView with menu with one custom layout item, but this custom layout is not visible in application.

This is the menu:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <item
        android:id="@+id/menu_shopping"
        android:icon="@drawable/ic_tab_list"
        android:title="@string/shopping" />

    <item
        android:id="@+id/menu_measurement"
        android:icon="@drawable/ic_tab_measure"
        android:title="@string/measurement" />

    <item
        android:id="@+id/menu_notifications"
        android:title="@string/notifications"
        app:actionLayout="@layout/item_action_notification" />

    <item
        android:id="@+id/menu_more"
        android:icon="@drawable/ic_tab_more"
        android:title="@string/more" />

</menu>

This is my custom layout:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="45dp"
    android:layout_height="50dp"
    android:background="@drawable/ic_tab_notifications">

    <RelativeLayout
        android:layout_width="22dp"
        android:layout_height="22dp"
        android:background="@drawable/red_circle"
        android:foregroundGravity="center">

        <TextView
            android:id="@+id/notification_count"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="0"
            android:textColor="@color/white"
            android:textSize="10sp" />

    </RelativeLayout>

</FrameLayout> 

This is activity layout:

<android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:itemTextColor="@color/colorPrimaryDark"
    app:menu="@menu/menu_main" />

Any ideas? Thanks!

0条回答
登录 后发表回答