Creating custom notification with xamarin.android

Deadly 提交于 2020-01-04 11:50:52

问题


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 ?


回答1:


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



来源:https://stackoverflow.com/questions/40045499/creating-custom-notification-with-xamarin-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!