我最近嘗試使用 Xamarin 和 Visual Studio 2019 在我的應用程式中使用自定義 ShellRenderer 自定義選項卡欄。我發現這個問題有人完全按照我的需要進行,并且該問題的答案非常詳細地解釋了它。
現在,我的問題是,在嘗試構建應用程式時,出現以下錯誤:
“CustomBottomNavAppearance”未實作介面成員“IShellBottomNavViewAppearanceTracker.SetAppearance(BottomNavigationView,IShellAppearanceElement)”(錯誤代碼 CS0535,第 32 行)
現在,另一個問題中的用戶提供的示例專案在我的機器上完美運行,但在我的專案中實作它卻不起作用,盡管它們實際上是相同的。
我希望這對于高級用戶來說是非常明顯的,對此我感到很抱歉,我仍在學習并希望現在就實作此功能,即使我的技能可能不允許我這樣做。
提前感謝您的任何回復!
這是我的“MyShellRenderer.cs”類:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Google.Android.Material.BottomNavigation;
using MyProject;
using MyProject.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(AppShell), typeof(MyShellRenderer))]
namespace MyProject.Droid
{
public class MyShellRenderer : ShellRenderer
{
public MyShellRenderer(Context context) : base(context)
{
}
protected override IShellBottomNavViewAppearanceTracker CreateBottomNavViewAppearanceTracker(ShellItem shellItem)
{
return new CustomBottomNavAppearance();
}
}
public class CustomBottomNavAppearance : IShellBottomNavViewAppearanceTracker
{
public void Dispose()
{
}
public void ResetAppearance(BottomNavigationView bottomView)
{
}
public void SetAppearance(BottomNavigationView bottomView, ShellAppearance appearance)
{
IMenu myMenu = bottomView.Menu;
IMenuItem myItemOne = myMenu.GetItem(0);
if (myItemOne.IsChecked)
{
myItemOne.SetIcon(Resource.Drawable.icon_about);
}
else
{
myItemOne.SetIcon(Resource.Drawable.icon_feed);
}
}
}
}
編輯:我剛剛發現這個問題實際上只存在于 Android 版本(好吧,iOS 版本至少不會拋出錯誤)。
更新:我已經能夠通過使用“使用 Google.Android.Material.BottomNavigation;”來解決這個問題。“使用 Android.Support.Design.Widget;”。我猜舊版本現在已棄用,僅適用于 4.xx 版本,而不適用于我的 5.xx 版本。感謝大家!
uj5u.com熱心網友回復:
根據this docs,錯誤does not implement interface member Errorcode CS0535意味著一個類必須實作它派生的介面的所有成員,或者被宣告為抽象的。所以問題必須是該方法SetAppearance沒有正確實作。當我洗掉或注釋該SetAppearance方法時,會出現錯誤.
解決方案是使用using Google.Android.Material.BottomNavigation而不是使用Android.Support.Design.Widget.
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/488543.html
