【问题标题】:How to customize header template in xamarin forms如何在 xamarin 表单中自定义标题模板
【发布时间】:2015-10-12 07:16:49
【问题描述】:

我正在 Xamarin 表单中创建一个需要自定义标头的应用程序。是否可以在 Xamarin 表单中自定义带有背景图像的标题?

【问题讨论】:

  • 你在说什么标题?
  • 我的意思是导航栏。
  • 您可以在主题中更改它或将完全不同的项目设置到android的操作栏中。

标签: c# android ios mobile xamarin


【解决方案1】:

您可能应该从 Xamarin 论坛查看此解决方案 - NavigationBar Background Image Render Android,这似乎是适用于 iOS 和 Android 的跨平台解决方案。它可以通过创建自定义渲染来工作,这是在 X.F 中进行任何自定义的最佳方式

安卓:

[assembly: ExportRenderer(typeof(ContentPage), typeof(ContentPageRenderer))]
    namespace MyApp.Renderers
    {
        public class ContentPageRenderer : PageRenderer
        {
            protected override void OnLayout(bool changed, int l, int t, int r, int b)
            {
                    base.OnLayout(changed, l, t, r, b);
                    var actionBar = ((Activity)Context).ActionBar;
                    actionBar.SetBackgroundDrawable(Resources.GetDrawable(Resource.Drawable.YourImageInDrawable));
            }
        }
    }

iOS:

[assembly: ExportRenderer(typeof(CustomNavigationPage), typeof(BlueNavigationRenderer))]
    namespace MobileCRM.iOS.Renderers
    {
        public class BlueNavigationRenderer : NavigationRenderer
        {

            public override void ViewDidLoad()
            {
                base.ViewDidLoad();

                this.NavigationBar.BarTintColor = UIColor.FromPatternImage(UIImage.FromFile("topbar_bg@2x.png"));
             }
          }
     }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-15
    相关资源
    最近更新 更多