Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: add badge to icons internal to my app

Tags:

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

like image 911
Michael_19 Avatar asked Apr 09 '10 19:04

Michael_19


People also ask

How do I put an app icon on my Android app?

Navigate to the resources directory (app > src > main > res) and expand out some of the mipmap folders. These mipmap folders are where you should put the launcher icon assets for your Android app.


2 Answers

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.

like image 153
alexanderblom Avatar answered Jan 18 '23 22:01

alexanderblom


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> 
like image 32
ranjit patel Avatar answered Jan 19 '23 00:01

ranjit patel