5

I want to design the following UI. Can anybody give me an example or suggest some source code for implementation?

Icon I want

blahdiblah
  • 30,909
  • 18
  • 92
  • 149
Altaf
  • 4,956
  • 10
  • 35
  • 54
  • What is it that you want done? The icon, the text, the symbol in the corner, the numbering? The code behind it or the graphics? – Tobbe Dec 12 '11 at 15:23
  • 2
    I'm 100% confident that I answered this question here already. Please search a bit around, the answer is definitely on SO. –  Dec 12 '11 at 15:23
  • @Tobbe I just want the graphics i-e the xml – Altaf Dec 12 '11 at 15:26

5 Answers5

9

Here is Project on Git Hub regarding showing badges on different items, but inside your application (i.e TextView, TabHost, ImageView etc)

About showing the badge on application icon, this is not possible, because this is not android way of showing notifications. The android framework supports handling notifications using Status bar Notifications

Adil Soomro
  • 36,617
  • 9
  • 98
  • 146
  • BUt sms icon has notification on icon and how it's work if is not android way ??????????? – Big.Child Aug 12 '13 at 08:24
  • Yes, some of samsung android devices show the icon badge in selected apps. It may be vendor specific. what device, os and vendor are you talking about? – Adil Soomro Aug 13 '13 at 06:43
  • I have Samsung Galaxy Ace and Android Version is 2.3.3. Can you tell my how to do such app icon notification ? I need samples, if you know where to see. – Big.Child Aug 13 '13 at 08:10
  • 1
    @Big.Child actually android doesn't support it. Have a look at this post: [How does Facebook add badge numbers on app icon in Android?](http://stackoverflow.com/a/17511840/593709), however you can use android widget as icon as [suggested here by Jin35](http://stackoverflow.com/a/8937758/593709) – Adil Soomro Aug 13 '13 at 08:26
6

If you want to set up the notification icon on the top-left corner it is as simple as the next piece of code:

Bitmap1 must be bigger than bitmap2, and in your case I would advise it to be a PNG image with transparent background to allow the notification bubble be outside the rest of the image.

        private Bitmap overlay(Bitmap bitmap1, Bitmap bitmap2) {
            Bitmap bmOverlay = Bitmap.createBitmap(bitmap1.getWidth(), bitmap1.getHeight(), bitmap1.getConfig());
            Canvas canvas = new Canvas(bmOverlay);
            canvas.drawBitmap(bitmap1, new Matrix(), null);
            canvas.drawBitmap(bitmap2, new Matrix(), null);
            return bmOverlay;
        }

Otherwise if you want it on the right-top corner you should try any of the others specifications for Canvas.drawBitmap.

For example:

canvas.drawBitmap(Bitmap bitmap, float left, float top, Paint paint);

Try doing something like:

private Bitmap overlay(Bitmap bitmap1, Bitmap bitmap2) {
            Bitmap bmOverlay = Bitmap.createBitmap(bitmap1.getWidth(), bitmap1.getHeight(), bitmap1.getConfig());
            Canvas canvas = new Canvas(bmOverlay);
            canvas.drawBitmap(bitmap1, new Matrix(), null);
            canvas.drawBitmap(bitmap2, bitmap1.getWidth()-bitmap2.getWidth(), 
                              0,null);
            return bmOverlay;
        }

If all you wanted was how to do it on XML, then you should create a RelativeLayout and then on it add both images and align the notification bubble to the right. And that should do the trick. You would've still have to have a PNG image with the transparent background.

I hope that would be enough for what you want to do.

fsschmitt
  • 584
  • 5
  • 10
2

Here is your source code for this app widget icon badge count display.

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_widget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dip"
android:focusable="true" >

<ImageView
    android:id="@+id/icon"
    android:layout_width="60dip"
    android:layout_height="60dip"
    android:layout_marginTop="8dp"
    android:background="@drawable/logo"
    android:contentDescription="image"
    android:scaleType="center" />

<TextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/icon"
    android:gravity="center"
    android:paddingLeft="3dp"
    android:paddingTop="10dp"
    android:shadowColor="#000000"
    android:shadowDx="1"
    android:shadowDy="1"
    android:shadowRadius="1.5"
    android:text="@string/app_name"
    android:textColor="#FFF" />

<TextView
    android:id="@+id/txt_count"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="-10dip"
    android:layout_toRightOf="@+id/icon"
    android:background="@drawable/badge_count2"
    android:contentDescription="badge"
    android:gravity="center"
    android:text="1"
    android:textColor="@color/White"
    android:textStyle="bold" />

</RelativeLayout>

and also you need this badge_count2.xml drawable file.

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >

<solid android:color="@color/red" >
</solid>

<stroke
    android:width="2dp"
    android:color="#FFFFFF" >
</stroke>

<padding
    android:bottom="2dp"
    android:left="7dp"
    android:right="7dp"
    android:top="3dp" />

<corners android:radius="10dp" >
</corners>

M D
  • 46,860
  • 8
  • 87
  • 108
2

You can use a RelativeLayout with two children, one for the icon and one for the badge. The icon needs extra padding so that the badge is slightly outside of it. The badge is positioned aligned with parentTop and parentRight.

David Burström
  • 1,563
  • 14
  • 14
0

here is a simple library available support in multiple devices like sony,samsung,moto etc...try this...this will work...i tried and is working fine... http://github.com/leolin310148/ShortcutBadger

dreamdeveloper
  • 1,176
  • 1
  • 13
  • 20