简体   繁体   English

Android:如何为图标创建通知徽章?

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

I have an ImageView like this:我有一个这样的ImageView

<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 ?如何在此ImageView右上角添加徽章图像? Is it possible to add a secondary image on the same ImageView ?是否可以在同一个ImageView上添加次要图像?

Example image:示例图像:

在此处输入图片说明

This is very simple UI, which you can do with help of two separate image view in one Parent Layout.这是一个非常简单的用户界面,您可以在一个父布局中的两个独立图像视图的帮助下完成。 i give you one simple idea below, but you can try any other way to doing same:我在下面给你一个简单的想法,但你可以尝试任何其他方式来做同样的事情:

<RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/image1"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:src="@android:drawable/btn_dialog"/>

    <ImageView
        android:id="@+id/image2"
        android:layout_width="15dp"
        android:layout_height="15dp"
        android:layout_toEndOf="@+id/image1"
        android:layout_marginLeft="-15dp"
        android:src="@android:drawable/btn_dialog"/>

</RelativeLayout>

Just change your image source in place of src in both image view.只需在两个图像视图中更改图像源代替src the 1st image view display main (large) image, and the 2nd one display small image which is on top of right corner.一个图像视图显示主(大)图像,第二个显示位于右上角的小图像。

Yes its possible try this是的,它可能试试这个

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" 
android:orientation="horizontal"
android:layout_height="wrap_content" >

<ImageView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="2dp"
    android:id="@+id/historyIcon"
    tools:src="@drawable/to_delete" />
<ImageView
    android:padding="10dp"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

</RelativeLayout>
    <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图像将是在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Android应用程序(如iPhone)上创建通知图标徽章 - How to create notification icon badge on Android apps (like iPhone) 如何以编程方式在Android上的应用程序图标上显示推送通知徽章计数? - How to show push notification badge count on app icon in android programmatically? 如何使用 Ionic 2 在 Android 应用程序图标中增加徽章计数通知? - How to increase badge count notification in the Android app icon using Ionic 2? 如何在后台在Android应用程序图标上计算推送通知消息徽章 - How to count Push notification message badge on android app icon in background 向Android设备添加通知标志图标 - Adding a Notification Badge Icon to Android Devices 在android中的app图标上添加通知徽章 - adding notification badge on app icon in android Android App Icon中的通知计数徽章 - Notification Count Badge in Android App Icon 在 Android 中计数的 React Native 通知徽章图标 - React Native notification badge icon with counting in Android 如何设置小通知图标徽章 - How to set tiny notification icon badge 我们如何在Android中以编程方式为“锁定屏幕通知和徽章图标”等应用启用通知设置 - How can we enable notification setting in android for app like “lock screen notification and badge icon” programatically
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM