简体   繁体   English

使用 xamarin.android 创建自定义通知

[英]Creating custom notification with xamarin.android

I have been trying to make a fully custom notification with Xamarin.android.我一直在尝试使用 Xamarin.android 制作完全自定义的通知。
My project targets min API of 14, so expended notification are supported.我的项目针对 14 个最小 API,因此支持扩展通知。 I'm trying to achieve the same look for all API's so i'm using Android.Support.V4.App.NotificationCompat.Builder .我正在尝试为所有 API 实现相同的外观,因此我正在使用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.我发现你可以使用setCustomContentView来设置一个自定义视图,它会完全改变通知的布局,这就是我的目标。

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 .其中Resource.Layout.SingleNotificationLayout是通知的布局文件。我从MainActiviy运行此代码。代码是从这里修改的。

The error that i'm facing is that SetCustomBigContentView is not found, specifically :我面临的错误是SetCustomBigContentView ,特别是:

'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 .特别是https://www.nuget.org/packages/Xamarin.Android.Support.v4/24.2.1-rc1 ,其中包括一个新程序集: Xamarin.Android.Support.Compat This will include the method you're looking for:这将包括您正在寻找的方法:

EX: Looking through Xamarin.Android.Support.Compat in DotPeek EX:在Xamarin.Android.Support.Compat中查看 Xamarin.Android.Support.Compat

在此处输入图片说明

However it's not included in the current stable(23.4.0.1) as you can see here:但是,它不包含在当前的稳定版 (23.4.0.1) 中,正如您在此处看到的:

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

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM