[英]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.