簡體   English   中英

如何顯示帶有導航抽屜菜單項的指示器

[英]How to show an indicator with a navigation drawer menu item

我正在嘗試顯示帶有一些相關菜單項的計數指示器。 我該怎么做? 我嘗試為菜單項創建TextView子級,但是它們似乎不起作用。 這是我要實現的模型(請參見Gallery選項旁邊的通知程序)

在此處輸入圖片說明

如果您使用的是NavigationView

NavigationView提供了一種構建導航抽屜的便捷方法,包括使用菜單XML文件創建菜單項的能力。 通過使用app:actionLayout或使用MenuItemCompat.setActionView()為項目設置自定義視圖的功能,我們擴展了可能的功能。


<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header"
    app:menu="@menu/drawer_menu" />

抽屜_菜單.xml

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

    <group android:checkableBehavior="single">
        <item android:id="@+id/nav_item1"
            app:showAsAction="always"
            android:title=""
            app:actionLayout="@layout/menu_item_layout" />
    </group>
</menu>

menu_item_layout.xml

您可以根據需要自定義

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView android:id="@+id/tv_title"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_vertical"
        android:text="Item text" />
</RelativeLayout>

您可以創建FrameLayout在其中添加Titile TextView並在其上方添加Count TextView ,如下所示t

<FrameLayout>
    <TextView></TextView> //your titile TextView
    <TextView></TextView> //your count TextView which has gravity of top right and circular background drawable
</FrameLayout>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM