【问题标题】:Android: add badge to icons internal to my appAndroid:将徽章添加到我的应用程序内部的图标
【发布时间】:2010-04-09 19:41:18
【问题描述】:

我正在尝试为我的 android 应用程序中的图标添加徽章。例如在 facebook 应用程序(适用于 iPhone)中,在主页中,未决请求的数量显示在请求图标上。

有人可以提供有关如何执行此操作的任何链接/想法吗?

谢谢

【问题讨论】:

标签: java android eclipse


【解决方案1】:

如果你真的想这样做。使用FrameLayout,其中包含一个带有您的图标的ImageView,以及一个带有九个可绘制对象的TextView,在右上角作为背景。如果您希望徽章稍微超出图标,请为 ImageView 添加边距。

【讨论】:

【解决方案2】:

感谢 Alexanderblom 的提示。我使用该逻辑并设法在内部图像图标上创建徽章。这是 xml 文件。您只需在可绘制对象上创建一个红色圆圈。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/frameLayout1"
    android:layout_width="wrap_content"
   android:layout_height="wrap_content" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />


    <TextView
        android:id="@+id/textView1"
        android:layout_width="20dip"
        android:layout_height="20dip"
        android:text="5"
        android:textColor="@color/black"
        android:textStyle="bold"
        android:padding="2sp"
        android:gravity="center"
        android:background="@drawable/circle"
        android:layout_gravity="top|right" />

</FrameLayout>

circle.xml 是

<item>
    <shape android:shape="oval">
        <solid android:color="@android:color/black" />
    </shape>
</item>
<item android:top="1dp" android:left="1dp" android:right="1dp" android:bottom="1dp">
    <shape android:shape="oval">
        <solid android:color="@color/Red" />

    </shape>
</item>

【讨论】:

    【解决方案3】:

    Android 不支持图标上的徽章。

    相反,它提供了通知系统(通知栏中的图标等),以及创建可以添加到用户“桌面”的widgets 的能力。

    【讨论】:

      【解决方案4】:

      检查这个库,它将徽章添加到图标/按钮/选项卡

      https://github.com/jgilfelt/android-viewbadger

      【讨论】:

        【解决方案5】:

        试试这个,适用于 Sony、Samsung、LG、HTC、小米、ASUS、ADW、APEX 和 NOVA Launchers。

        https://github.com/leolin310148/ShortcutBadger

        【讨论】:

          【解决方案6】:

          按照以下定义将通知计数添加到应用图标的步骤

          步骤:

          1. 将 mavenCentral 添加到您的构建脚本中。

            存储库 { mavenCentral() }

          2. 在您的应用程序 gradle 中添加依赖项。

            依赖{ 编译'me.leolin:ShortcutBadger:1.1.4@aar' 要么 编译'me.leolin:ShortcutBadger:1.1.3@aar' }

          3. 添加以下代码以在应用图标上显示通知计数:

            int badgeCount = 1; ShortcutBadger.applyCount(context, badgeCount); //对于 1.1.4 要么 ShortcutBadger.with(getApplicationContext()).count(badgeCount); //对于 1.1.3

          4. 如果你想移除徽章

            ShortcutBadger.removeCount(context); //对于 1.1.4 ShortcutBadger.with(getApplicationContext()).remove(); //对于 1.1.3 要么 ShortcutBadger.applyCount(context, 0); //对于 1.1.4 ShortcutBadger.with(getApplicationContext()).count(0); //对于 1.1.3

          【讨论】:

            猜你喜欢
            • 2010-12-07
            • 1970-01-01
            • 2011-02-23
            • 2014-11-09
            • 2013-10-05
            • 2019-08-31
            • 2017-03-02
            • 1970-01-01
            • 2015-12-04
            相关资源
            最近更新 更多