使用 xamarin.android 创建自定义通知 [英] Creating custom notification with xamarin.android

查看:81
本文介绍了使用 xamarin.android 创建自定义通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用 Xamarin.android 制作完全自定义的通知.
我的项目针对 14 个最小 API,因此支持扩展通知.我正在尝试为所有 API 实现相同的外观,因此我正在使用 Android.Support.V4.App.NotificationCompat.Builder.

我发现您可以使用

但是,正如您在此处看到的那样,它并未包含在当前的稳定版 (23.4.0.1) 中:

EX:在 DotPeek 中查看 Xamarin.Android.Support.v4

I have been trying to make a fully custom notification with Xamarin.android.
My project targets min API of 14, so expended notification are supported. I'm trying to achieve the same look for all API's so i'm using Android.Support.V4.App.NotificationCompat.Builder.

I have found out that you can use setCustomContentView to set a custom View that will change the layout of the notification complitly, which is what i aim for.

Here is the code that i have tried to run:

RemoteViews widgetLayout = new RemoteViews(PackageName,Resource.Layout.SingleNotificationLayout);

NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .SetCustomBigContentView(widgetLayout);

notificationManager.Notify(notificationId, builder.Build());

Which Resource.Layout.SingleNotificationLayout is a layout file for the notification.Im running this code from MainActiviy.Code is modified from here.

The error that i'm facing is that SetCustomBigContentView is not found, specifically :

'NotificationCompat.Builder' does not contain a definition for 'SetCustomBigContentView' and no extension method 'SetCustomBigContentView' accepting a first argument of type 'NotificationCompat.Builder' could be found (are you missing a using directive or an assembly reference?)

Here are my installed packages:

<package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="23.4.0.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Design" version="23.4.0.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.v14.Preference" version="23.4.0.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.v4" version="23.4.0.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.v7.AppCompat" version="23.4.0.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.v7.GridLayout" version="23.4.0.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.v7.Preference" version="23.4.0.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.v7.RecyclerView" version="23.4.0.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Vector.Drawable" version="23.4.0.1" targetFramework="monoandroid70" />

What am i missing ? Is the equivalent function named differently ?

解决方案

You will need to use the latest pre-release packages for the support libraries. Specifically https://www.nuget.org/packages/Xamarin.Android.Support.v4/24.2.1-rc1 which includes a new assembly: Xamarin.Android.Support.Compat. This will include the method you're looking for:

EX: Looking through Xamarin.Android.Support.Compat in DotPeek

However it's not included in the current stable(23.4.0.1) as you can see here:

EX: Looking through Xamarin.Android.Support.v4 in DotPeek

这篇关于使用 xamarin.android 创建自定义通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆