2015-09-29 27 views
4

我想创建一个通知视图就像whatsapp或短信notification.How我可以实现这一点。通知像WhatsApp或短信应用程序android

enter image description here

我有什么搜索到现在

CroutonCan found here

这将显示在运行活动及以下操作栏crouton。 如果我的活动没有运行,或者我在其他活动中,这个句柄怎么办。

Toast: 这看起来不像烤面包。它只显示在底部或中心。

Dialog: 这可以这样做,但这会模糊应用程序。并禁用背景。我不想要这个

任何解决方案将不胜感激。

感谢

+0

你需要的是一个通知。(http://developer.android.com/guide /topics/ui/notifiers/notifications.html)什么是应用程序和所有其他应用程序都有自己的定制通知..如果您正在寻找一个定制的通知。我可以帮助你。但我不明白你需要什么。 –

回答

3

你在上面“抬头notificcation”

链接(后,Android 4.3加入功能)寻找图像中:通报heads up notification

设置优先级为高,以显示它在屏幕上头 希望这可以帮助

+0

哎如何从4.3支持它,因为我认为它是从5.0有没有任何支持lib或东西请让我知道我想要在我的应用程序 – Pavan

+1

实施更新您的链接,链接是死/错。 – shailesh

+0

链接已更新 –

11

这是一个平视通知于Android棒棒糖 这里工作你检查如何显示通知,您可以在这里看到http://developer.android.com/guide/topics/ui/notifiers/notifications.html 以及平视你必须设置通知优先如下

.setPriority(Notification.PRIORITY_HIGH) 

希望它有帮助

编辑Nov-17

Notification.PRIORITY_HIGH已在API级别26中弃用。请改为使用IMPORTANCE_HIGH

+0

如果您看到屏幕快照,我没有拉动我的通知托盘。这发生如 1.消息来了Crouton显示然后它出现在状态栏上的通知图标上。 – shailesh

+0

是的,这是抬头通知。我将添加代码作为答案。谢谢 – shailesh

+0

现在'Notification.PRIORITY_MAX'已弃用。 – pRaNaY

5

它可以通过Headsup通知完成。这是Andorid的大号 功能,这样通过代码在这里是演示

Notification createNotification(boolean makeHeadsUpNotification) { 
    Notification.Builder notificationBuilder = new Notification.Builder(this) 
      .setSmallIcon(R.drawable.ic_launcher) 
      .setPriority(Notification.PRIORITY_DEFAULT) 
      .setContentTitle("Sample Notification") 
      .setContentText("This is a normal notification."); 

    if(Build.VERSION.SDK_INT> Build.VERSION_CODES.KITKAT) 
    { 
     notificationBuilder.setCategory(Notification.CATEGORY_MESSAGE); 
    } 
    if (makeHeadsUpNotification) { 
     Intent push = new Intent(); 
     push.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     push.setClass(this, IndexActivity.class); 

     PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(this, 0, 
       push, PendingIntent.FLAG_CANCEL_CURRENT); 
     notificationBuilder 
       .setContentText("Heads-Up Notification on Android L or above.") 
       .setFullScreenIntent(fullScreenPendingIntent, true); 
    } 
    return notificationBuilder.build(); 
} 

你可以这样调用它

NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context 
      .NOTIFICATION_SERVICE); 
    mNotificationManager.notify(NOTIFICATION_ID, createNotification(
      true)); 
+0

我有疑问,如果应用程序关闭我会收到通知..? –

+0

@Vishal为什么不会,这是通知如何从API 21进一步在屏幕上填充。 – shailesh

相关问题