Search code examples
androidandroid-layoutandroid-imageview

Android: how to create a notification badge for an icon?


I have an ImageView like this:

<ImageView android:id="@+id/historyIcon"
    tools:src="@drawable/to_delete"
    android:scaleType="centerCrop"
    android:layout_alignParentLeft="true"
    android:layout_width="32dp"
    android:layout_height="32dp" />

How can I add a badge image on the top right corner of this ImageView? Is it possible to add a secondary image on the same ImageView?

Example image:

enter image description here


Solution

  •     <RelativeLayout
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:gravity="center">
    
        <ImageView
            android:id="@+id/xx"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="10dp"
            android:src="@mipmap/mprofilelogo"/>
    
    
        <ImageView
            android:id="@+id/ss"
            android:layout_width="25dp"
            android:layout_height="25dp"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:background="@mipmap/ccc"
            android:src="@null"/>
    
    </RelativeLayout>
    

    Image will be enter image description here