我正在尝试向我的android应用程序中的图标添加徽章。例如在Facebook应用程序(iPhone版)中,在主页中,挂起请求的数量显示在请求图标上。Android:为我的应用程序内部的图标添加徽章
有人可以提供任何链接/想法如何做到这一点?
谢谢
我正在尝试向我的android应用程序中的图标添加徽章。例如在Facebook应用程序(iPhone版)中,在主页中,挂起请求的数量显示在请求图标上。Android:为我的应用程序内部的图标添加徽章
有人可以提供任何链接/想法如何做到这一点?
谢谢
Android不支持图标上的徽章。
相反,它提供通知系统(通知栏中的图标等),以及创建可添加到用户“桌面”的widgets的功能。
如果你真的想这样做。使用FrameLayout
,其中包含一个ImageView
与您的图标和一个TextView
以及一个可绘制的九个方块作为背景在右上角。如果您希望徽章稍微偏离图标,请将边距添加到ImageView
。
非常酷,必须安装那一个。 – synic 2010-04-09 20:43:19
我如何使用小部件下的文本创建背景? – chrisonline 2011-05-25 14:29:40
@alexanderblom - http://alexanderblom.se/gmail-unread-count/现在不能工作..你能否提供一个新的..实际上我希望这个功能可以在TabHost – 2011-11-28 07:27:08
感谢Alexanderblom,为hints.i使用该逻辑并设法在内部imageicon上创建徽章。这里是xml文件。您必须在drawable上创建一个红色圆圈。
<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>
检查这个库,增加了徽章的图标/按钮/标签
试试这一个,是良好的索尼,三星,LG,HTC,小米,华硕,ADW,APEX和NOVA发射器。
按照以下定义附加的通知计数步骤应用程序图标
步骤:
添加mavenCentral到您的构建脚本。
库{mavenCentral()}
添加依赖于你的应用程序gradle这个。
依赖性{ 编译 'me.leolin:ShortcutBadger:[email protected]' 或 编译 'me.leolin:ShortcutBadger:[email protected]' }
添加下面的代码在应用图标上显示通知计数:
int badgeCount = 1; ShortcutBadger.applyCount(context,badgeCount); // for 1.1.4 或 ShortcutBadger.with(getApplicationContext())。count(badgeCount); // for 1.1。3
如果你想删除的徽章
ShortcutBadger.removeCount(背景); // for 1.1.4 ShortcutBadger.with(getApplicationContext())。remove(); // for 1.1.3 or ShortcutBadger.applyCount(context,0); // for 1.1.4 ShortcutBadger.with(getApplicationContext())。count(0); // for 1.1.3
2016年有什么变化吗?我们现在有图书馆吗? – 2016-09-17 01:41:47
类似的问题与很好的回答:http://stackoverflow.com/questions/17565307/ – porfirion 2016-10-06 12:19:06