[英]Notification Icon not display properly with Xamarin Android on Lollipop
我在设置通知图像以正确显示时遇到问题。
下面是原始图像,文件路径:
myApp\\Resources\\drawable\\Icon.png
尺寸:72x72 像素,32 位深度
问题:
它显示如下。
下面是代码。 该代码似乎可以正常显示它的先前版本。
public class MyServiceConnection : Java.Lang.Object, IServiceConnection
{
private string _appName;
public MyServiceConnection(string appName)
{
_appName = appName;
}
public void OnServiceConnected(ComponentName name, IBinder service)
{
var intent = new Intent(Application.Context, typeof(ManifestActivity));
intent.AddFlags(ActivityFlags.ClearTop);
var pendingIntent = PendingIntent.GetActivity(Application.Context, 0, intent, PendingIntentFlags.UpdateCurrent);
var notificationBuilder = new NotificationCompat.Builder(Application.Context)
.SetSmallIcon(Resource.Drawable.Icon)
.SetContentTitle(_appName)
.SetAutoCancel(true)
.SetContentIntent(pendingIntent);
var notificationManager = NotificationManager.FromContext(Application.Context);
var notification = notificationBuilder.Build();
notificationManager.Notify(1, notification);
var serviceBinder = service as MyService.Binder;
serviceBinder.StartForeground(1, notification);
}
public void OnServiceDisconnected(ComponentName name)
{
}
}
环境:
android:minSdkVersion="15" android:targetSdkVersion="27"
更新
正如我所提到的,使用相同的代码和相同的 png 文件,现在在单独的 apk 上工作。 一旦为第二个分支创建了代码,问题就会出现在第二个分支上。
更新 2
我通过在下面更改来修复它
Project Properties -> Android Manifest -> Target Android Version to "Use Compile using SDK version"
结果如下:
android:minSdkVersion="15"
“使用使用 SDK 版本编译”是什么意思? 安装在 Lollipop 上时使用的是什么目标版本?
因为谷歌对android5.0及以上(不包括5.0)做了限制,为了统一系统风格。 之后状态栏的图标就不能随意使用色彩丰富的图片了。 它只能以两种颜色出现,白色和透明。
您可以通过两种方式进行:
1.通过降低targetSdkVersion方法显示彩色图标,但不支持降低targetSdkVersion方法。(不推荐)
2.分别设置setSmallIcon(制作另一个透明背景的白色图标)
if(Android.OS.Build.VERSION.SdkInt> BuildVersionCodes.Lollipop){
// white icon with a transparent background
notificationBuilder.SetSmallIcon(Resource.Drawable.ic_aphla_logo);
} else {
// icon image
notificationBuilder.SetSmallIcon(Resource.Drawable.ic_logo);
}
可以参考这个: Android 5 Lollipop 通知栏图标变白
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.