繁体   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