我正在开发一个应用程序,我在那里为用户创建通知.我希望图标在状态栏中显示为白色,但在下拉通知菜单中显示时显示为蓝色.以下是Google Store应用程序执行相同操作的示例.
状态栏中的白色通知:
下拉菜单中的彩色通知:
我怎么能复制这个?我需要设置哪些属性?
编辑: 这是我当前的代码 - 我使图像全白,透明背景,所以它在状态栏中看起来很好,但在通知中,图像仍然是相同的白色:
private NotificationCompat.Builder getNotificationBuilder() {
return new NotificationCompat.Builder(mainActivity)
.setDeleteIntent(deletedPendingIntent)
.setContentIntent(startChatPendingIntent)
.setAutoCancel(true)
.setSmallIcon(R.drawable.skylight_notification)
.setColor(ContextCompat.getColor(mainActivity, R.color.colorPrimary))
.setContentTitle(mainActivity.getString(R.string.notification_title))
.setContentText(mainActivity.getString(R.string.notification_prompt));
}
Run Code Online (Sandbox Code Playgroud) 我有一个CharFieldmaxlength为300 的标签,但我需要为默认输入保留100个字符,但我希望用户能够通过输入文本框设置剩余的200个字符.我的工厂是将模型中的字段的最大长度设置为300,并在我的表单中为输入创建一个小部件,将用户的输入限制为200个字符.
但是,我做了一些测试,发现我无法从charfield本身的maxlength更改输入字段的最大长度.有谁知道怎么做?
models.py
class Video(models.Model):
title = models.CharField(max_length=50)
tags = models.CharField(max_length=200)
Run Code Online (Sandbox Code Playgroud)
form.py
class VideoForm(forms.ModelForm):
class Meta:
model=Video
fields=['title','description','authorId','tags','video','thumbnail']
#a widget is django's representation of an html input element
widgets = {
'tags': forms.Textarea(attrs={'cols': 80, 'rows': 20,'maxlength':5}),
}
Run Code Online (Sandbox Code Playgroud)
上面代码生成的html textarea是<textarea cols="80" id="id_tags" maxlength="200" name="tags" rows="20"></textarea>,但我希望它maxlength是5.
我正在使用Xamarin和iOS,但是在通知方面我遇到了很多麻烦.我可以创建一个发送到通知中心的本地推送通知,但没有声音或指示通知实际到达.如何使通知成为警报通知,以便在进入通知中心之前显示在屏幕上?
这是我正在生成通知的代码:
//create notification
var notification = new UILocalNotification ();
notification.AlertAction = "Open App";
notification.AlertTitle = "App";
notification.AlertBody = "There has been activity in the app";
notification.SoundName = UILocalNotification.DefaultSoundName;
//display notification
UIApplication.SharedApplication.ScheduleLocalNotification (notification);
Run Code Online (Sandbox Code Playgroud)
编辑:问题不仅仅是声音,而是没有收到警报的反馈,它只是静默地出现在通知中心.我也要求使用此代码的权限:
var settings = UIUserNotificationSettings.GetSettingsForTypes(
UIUserNotificationType.Alert
| UIUserNotificationType.Badge
| UIUserNotificationType.Sound,
new NSSet());
UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
UIApplication.SharedApplication.RegisterForRemoteNotifications();
Run Code Online (Sandbox Code Playgroud)