[英]How to show an indicator with a navigation drawer menu item
如果您使用的是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" />
<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>
您可以根据需要自定义
<?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.