I am trying to add badges to the icons in my android app. e.g. in the facebook app(for iPhone), in the home page the number of pending requests is shown on the requests icon.
Can someone provide any links/ideas on how to do this?
Thanks
I am trying to add badges to the icons in my android app. e.g. in the facebook app(for iPhone), in the home page the number of pending requests is shown on the requests icon.
Can someone provide any links/ideas on how to do this?
Thanks
If you really want to do it. Use a FrameLayout
which contains an ImageView
with your icon and a TextView
with a ninepatch drawable as background in the right corner. Add margins to the ImageView
if you want the badge to be a bit outside the icon.
Thanks Alexanderblom ,for the hints.i used that logic and manage to create badge on a internal imageicon.here is the xml file.and you have to just create a red circle on the 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>
and the circle.xml is
<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>
Try this one, is good for Sony, Samsung, LG, HTC, Xiaomi, ASUS, ADW, APEX and NOVA Launchers.
Follow below define steps for add notification count to app icon
Steps:
Add mavenCentral to your build script.
repositories { mavenCentral() }
Add dependencies in your app gradle.
dependencies { compile 'me.leolin:ShortcutBadger:1.1.4@aar' or compile 'me.leolin:ShortcutBadger:1.1.3@aar' }
Add the codes below for display notification count on app icon:
int badgeCount = 1; ShortcutBadger.applyCount(context, badgeCount); //for 1.1.4 Or ShortcutBadger.with(getApplicationContext()).count(badgeCount); //for 1.1.3
If you want to remove the badge
ShortcutBadger.removeCount(context); //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