【问题标题】:UI help for Notification on icon图标通知的 UI 帮助
【发布时间】:2011-12-12 15:21:09
【问题描述】:

我想设计以下 UI。谁能给我一个例子或建议一些实现的源代码?

【问题讨论】:

  • 你想要做什么?图标、文字、角落里的符号、编号?它背后的代码还是图形?
  • 我 100% 确信我已经在这里回答了这个问题。请搜索一下,答案肯定在SO上。
  • @Tobbe 我只想要图形,即 xml

标签: android user-interface android-layout android-widget


【解决方案1】:

Here is Project on Git Hub 关于在不同项目上显示徽章,但在您的应用程序中(即TextViewTabHostImageView 等)

关于在应用程序图标上显示徽章,这是不可能的,因为这不是 android 显示通知的方式。 android框架支持使用Status bar Notifications处理通知

【讨论】:

  • BUt 短信图标在图标上有通知,如果不是安卓方式它是如何工作的???????????
  • 是的,一些三星安卓设备在选定的应用程序中显示图标徽章。它可能是特定于供应商的。您指的是什么设备、操作系统和供应商?
  • 我有三星 Galaxy Ace,Android 版本是 2.3.3。你能告诉我如何做这样的应用程序图标通知吗?我需要样品,如果你知道去哪里看的话。
  • @Big.Child 实际上 android 不支持它。看看这篇文章:How does Facebook add badge numbers on app icon in Android?,但是你可以使用 android 小部件作为图标作为suggested here by Jin35
【解决方案2】:

如果你想在左上角设置通知图标,就像下一段代码一样简单:

Bitmap1 必须大于 bitmap2,在您的情况下,我建议它是具有透明背景的 PNG 图像,以允许通知气泡位于图像的其余部分之外。

        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;
        }

否则,如果您希望它位于右上角,您应该尝试 Canvas.drawBitmap 的任何其他规范。

例如:

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

尝试做类似的事情:

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;
        }

如果您只想在 XML 上执行此操作,那么您应该创建一个 RelativeLayout,然后在其上添加两个图像并将通知气泡对齐到右侧。这应该可以解决问题。您仍然必须拥有具有透明背景的 PNG 图像。

我希望这对你想做的事情来说已经足够了。

【讨论】:

  • +1 用于回答如何在 XML 中布局和实现。
【解决方案3】:

您可以使用具有两个子级的 RelativeLayout,一个用于图标,一个用于徽章。 该图标需要额外的填充,以便徽章稍微超出它。 徽章的位置与 parentTop 和 parentRight 对齐。

【讨论】:

    【解决方案4】:

    这是此应用小部件图标徽章计数显示的源代码。

        <?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>
    

    你还需要这个 badge_count2.xml 可绘制文件。

    <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>
    

    【讨论】:

      【解决方案5】:

      这里有一个简单的库,可支持多种设备,如索尼、三星、moto 等...试试这个...这将工作...我尝试过并且工作正常... http://github.com/leolin310148/ShortcutBadger

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-03-22
        • 2011-06-04
        • 1970-01-01
        • 2021-06-04
        • 1970-01-01
        • 1970-01-01
        • 2014-10-07
        • 1970-01-01
        相关资源
        最近更新 更多