【问题标题】:How to implement a badge counter on android hamburger menu icon [duplicate]如何在android汉堡菜单图标上实现徽章计数器[重复]
【发布时间】:2016-01-06 21:05:07
【问题描述】:

我正在尝试在汉堡菜单图标(即不是其他菜单图标)上实现计数器徽章。类似于 eBay 应用程序。如...

有人调查过吗?试图找出最干净的方法。

【问题讨论】:

  • 在菜单图标图像上方设置 textview..并设置圆形背景
  • 您能否详细说明,因为汉堡菜单图标是作为主题的一部分嵌入的。那么如何改变呢?
  • 在汉堡菜单图标上专门添加徽章并不是重复的。不是其他菜单图标

标签: android android-layout android-drawable android-menu navigation-drawer


【解决方案1】:

使用Toolbar Widget 非常简单,您可以按照以下示例来实现:

首先创建一个Oval shape

<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid android:color="#ff00"/>
</shape>

然后创建一个toolbar 小部件,如下所示:

<android.support.v7.widget.Toolbar
    android:layout_width="match_parent"
    android:layout_height="?actionBarSize"
    android:background="?colorPrimary">

    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent">

        <ImageView
            android:id="@+id/openMenu"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@drawable/ic_menu"/>

        <TextView
            android:id="@+id/badger"
            android:layout_width="16dp"
            android:layout_height="16dp"
            android:layout_gravity="end|right|top"
            android:layout_marginTop="10dp"
            android:background="@drawable/badge"
            android:gravity="center"
            android:text="1"
            android:textColor="@color/white"/>

    </FrameLayout>
</android.support.v7.widget.Toolbar>

【讨论】:

  • 我最终删除了现有的菜单图标并设置了一个带有徽章的新图标,如上述布局。谢谢
  • @k0sh 你能详细说明一下吗。我已经尝试过您的代码,但最终得到了两个汉堡包图标...:-/
  • @ban-geoengineering 如果您使用上述代码,请删除汉堡图标的编程设置。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-29
  • 2023-01-26
  • 1970-01-01
  • 1970-01-01
  • 2018-08-10
相关资源
最近更新 更多