Я пытался добавить значок в iOS. Я могу успешно добавить. Может кто-нибудь, пожалуйста, помогите в android. Обратите внимание, что я не хочу использовать навигацию по оболочке.
public class CustomTabbedPageHandler : Microsoft.Maui.Controls.Handlers.Compatibility.TabbedRenderer
{
public void UpdateTabBadges()
{
if (Element is MainTabbedPage customTabbedPage)
{
// Ensure that ViewController is not null
if (ViewController is UITabBarController tabBar && tabBar.TabBar != null)
{
for (int i = 0; i < customTabbedPage.Children.Count; i++)
{
var badgeCount = customTabbedPage.GetBadgeCount(i);
AddBadgeToTab(i, badgeCount);
}
}
}
}
public void AddBadgeToTab(int tabIndex, int count)
{
if (ViewController is UITabBarController tabBar)
{
try
{
// Check if the tabBar has items and if the tabIndex is valid
if (tabBar.TabBar.Items != null && tabBar.TabBar.Items.Length > tabIndex)
{
// Set the badge value
tabBar.TabBar.Items[tabIndex].BadgeValue = count > 0 ? count.ToString() : null;
}
}
catch (Exception ex)
{
// Optionally log the exception or handle it as needed
Console.WriteLine($"Error adding badge: {ex.Message}");
}
}
}
}
Вот для Android. но получение табличного макета всегда равно нулю.
public class CustomTabbedPageHandler : TabbedViewHandler
{
public override void UpdateValue(string property)
{
base.UpdateValue(property);
var tabs = Microsoft.Maui.ApplicationModel.Platform.CurrentActivity?.FindViewById(Microsoft.Maui.Resource.Id
.navigationlayout_bottomtabs);
var tabLayout = tabs?.GetChildAt(0);
if (tabLayout is TabLayout layout)
{
====//===
}
}
}
Не знаю, как мне получить доступ к вкладке и добавить туда значок.
Я пытался добавить значок в iOS. Я могу успешно добавить. Может кто-нибудь, пожалуйста, помогите в android. Обратите внимание, что я не хочу использовать навигацию по оболочке. [code]public class CustomTabbedPageHandler : Microsoft.Maui.Controls.Handlers.Compatibility.TabbedRenderer { public void UpdateTabBadges() { if (Element is MainTabbedPage customTabbedPage) { // Ensure that ViewController is not null if (ViewController is UITabBarController tabBar && tabBar.TabBar != null) { for (int i = 0; i < customTabbedPage.Children.Count; i++) { var badgeCount = customTabbedPage.GetBadgeCount(i); AddBadgeToTab(i, badgeCount); } } } }
public void AddBadgeToTab(int tabIndex, int count) { if (ViewController is UITabBarController tabBar) { try { // Check if the tabBar has items and if the tabIndex is valid if (tabBar.TabBar.Items != null && tabBar.TabBar.Items.Length > tabIndex) { // Set the badge value tabBar.TabBar.Items[tabIndex].BadgeValue = count > 0 ? count.ToString() : null; } } catch (Exception ex) { // Optionally log the exception or handle it as needed Console.WriteLine($"Error adding badge: {ex.Message}"); } } } } [/code] Вот для Android. но получение табличного макета всегда равно нулю. [code]public class CustomTabbedPageHandler : TabbedViewHandler { public override void UpdateValue(string property) { base.UpdateValue(property);
var tabs = Microsoft.Maui.ApplicationModel.Platform.CurrentActivity?.FindViewById(Microsoft.Maui.Resource.Id .navigationlayout_bottomtabs);
var tabLayout = tabs?.GetChildAt(0);
if (tabLayout is TabLayout layout) { ====//=== } }
} [/code] Не знаю, как мне получить доступ к вкладке и добавить туда значок.