该应用程序有3种不同的颜色主题。白色,黑色和灰色。有没有一种新的简单方法可以使用背景颜色动态更改汉堡图标?因此,如果主题是灰色或白色,则图标应该是黑色的,如果主题是黑色,则图标应该是白色的。我正在使用Xamarin.Forms PRISM。
请查看以下链接:
https://forums.xamarin.com/discussion/69113/how-can-i-change-the-hamburger-icon-for-another-one-in-xamarin-forms-for-android
或者你可以试试这个:-
[assembly: ExportRenderer(typeof(CustomIcon.Views.MainPage), typeof(IconNavigationPageRenderer))]
namespace CustomIcon.Droid
{
public class IconNavigation : MasterDetailPageRenderer
{
private static Android.Support.V7.Widget.Toolbar GetToolbar() => (CrossCurrentActivity.Current?.Activity as MainActivity)?.FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
protected override void OnLayout(bool changed, int l, int t, int r, int b)
{
base.OnLayout(changed, l, t, r, b);
var toolbar = GetToolbar();
if (toolbar != null)
{
for (var i = 0; i < toolbar.ChildCount; i++)
{
var imageButton = toolbar.GetChildAt(i) as ImageButton;
var drawerArrow = imageButton?.Drawable as DrawerArrowDrawable;
if (drawerArrow == null)
continue;
imageButton.SetImageDrawable(Forms.Context.GetDrawable(Resource.Drawable.newIcon));
}
}
}
}
}