如何在Android的xamarin表单中创建自定义导航栏like this?
我尝试过使用CustomNavigationRenderer并且有一个对SupportActionBar的引用(它在活动中不是null,也不是NavigationRenderer),但是当我尝试对操作栏应用任何更改时,它都没有做任何事情。我正在使用FormsAppCompatActivity。
答案 0 :(得分:1)
在下面尝试自定义Android上的导航栏
[assembly: ExportRenderer(typeof(NavigationPage), typeof(CustomeNavigationPageRenderer))]
namespace Trainer.Droid.AndroidControls
{
public class CustomeNavigationPageRenderer : NavigationPageRenderer
{
protected override void OnLayout(bool changed, int l, int t, int r, int b)
{
base.OnLayout(changed, l, t, r, b);
var toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>
(Resource.Id.toolbar);
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.menu_icon));
}
}
}
}
其中&#34; menu_icon&#34;是您选择的任何图标或图像
&安培;通过此
设置平铺Title = "Search Test";
在工具栏的左侧,如下所示
ToolbarItem new_tb = new ToolbarItem
{
Icon = "cart.png",
Order = ToolbarItemOrder.Primary,
Command = new Command(() => root())
};
ToolbarItems.Add(new_tb);