[英]Notification like whatsapp or sms app android
I want to create a Notification view just like whatsapp or sms notification.How can i achieve that.我想创建一个通知视图,就像 whatsapp 或短信通知一样。我怎样才能做到这一点。
What I have search till now到目前为止我所搜索的
Crouton : Can found here面包丁:可以在这里找到
this will show a crouton at running activity and below to the action bar.这将在运行活动和下方的操作栏上显示一个面包丁。 if my activity not running or i am on the other activity how can this handle.如果我的活动没有运行或者我正在进行其他活动,这如何处理。
Toast : this is not looking like a toast.吐司:这看起来不像吐司。 It show only on bottom or center .它只显示在底部或中心。
Dialog : this can be done like this but this will blur the application. Dialog :这可以像这样完成,但这会使应用程序变得模糊。 and disable the background.并禁用背景。 And i don't want this我不想要这个
Any solution will appreciated.任何解决方案将不胜感激。
Thanks谢谢
it's a headsup notification works from android lollipop here you check how to show notification you can see here http://developer.android.com/guide/topics/ui/notifiers/notifications.html and for headsup you have to set notification priority as below这是一个来自 android 棒棒糖的单挑通知在这里你检查如何显示你可以在这里看到的通知http://developer.android.com/guide/topics/ui/notifiers/notifications.html并且对于单挑你必须将通知优先级设置为以下
.setPriority(Notification.PRIORITY_HIGH)
hope it helps希望能帮助到你
EDIT Nov-17编辑 11 月 17 日
Notification.PRIORITY_HIGH was deprecated in API level 26. use (NotificationManager.IMPORTANCE_HIGH) instead. Notification.PRIORITY_HIGH在 API 级别 26 中已弃用。请改用(NotificationManager.IMPORTANCE_HIGH) 。
It can be done via Headsup notification.它可以通过 Headsup 通知来完成。 It is feature of Andorid L so by code here is demo这是 Andorid L 的特性,所以这里的代码是演示
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();
}
you can call it like你可以这样称呼它
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context
.NOTIFICATION_SERVICE);
mNotificationManager.notify(NOTIFICATION_ID, createNotification(
true));
what you are looking in the image above "heads up notificcation" (feature added after android 4.3)您在上图中的“提示通知”(在 android 4.3 之后添加的功能)中看到的内容
link : heads up notification链接: 抬头通知
set priority of notification as high so as to display it on screen head hope this helps将通知的优先级设置为高,以便将其显示在屏幕头部希望这会有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.