gpt4 book ai didi

android - 如何显示带有抽屉导航菜单项的指示器

转载 作者:行者123 更新时间:2023-11-29 15:04:26 25 4
gpt4 key购买 nike

我正在尝试显示带有一些相关菜单项的计数指示器。我该怎么做呢?我尝试为菜单项创建 TextView 子项,但它们似乎不起作用。这是我想要实现的模型(请参阅 Gallery 选项旁边的通知程序)

enter image description here

最佳答案

如果你正在使用NavigationView

NavigationView provides a convenient way to build a navigation drawer, including the ability to creating menu items using a menu XML file. We’ve expanded the functionality possible with the ability to set custom views for items via app:actionLayout or using 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>

关于android - 如何显示带有抽屉导航菜单项的指示器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39673388/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com