sha*_*esh 4 notifications android dialog whatsapp crouton
我想创建一个通知视图就像whatsapp或短信通知.我怎么能实现这一点.
我到现在为止所搜索的内容
克鲁顿:可以在这里找到
这将在跑步活动中显示一个烤面包片,在操作栏下方显示.如果我的活动没有运行或我正在进行另一项活动,那么它如何处理.
吐司:这看起来不像吐司.它仅显示在底部或中心.
对话框:这可以这样做但这会使应用程序模糊.并禁用背景.我不想要这个
任何解决方案都将受
谢谢
Pav*_*van 11
这是一个从头脑通知工作从android棒棒糖这里你检查如何显示通知,你可以在这里看到http://developer.android.com/guide/topics/ui/notifiers/notifications.html 和对于抬头你必须设置通知优先级为下面
.setPriority(Notification.PRIORITY_HIGH)
Run Code Online (Sandbox Code Playgroud)
希望能帮助到你
编辑11月17日
Notification.PRIORITY_HIGH在API级别26中已弃用.请改用IMPORTANCE_HIGH.
它可以通过Headsup通知完成.它是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();
}
Run Code Online (Sandbox Code Playgroud)
你可以称之为
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context
.NOTIFICATION_SERVICE);
mNotificationManager.notify(NOTIFICATION_ID, createNotification(
true));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13569 次 |
| 最近记录: |