【问题标题】:different Custom navigation bar (action bar) for different pages in android xamarinandroid xamarin中不同页面的不同自定义导航栏(操作栏)
【发布时间】:2015-08-07 12:13:32
【问题描述】:

我正在尝试为不同的页面创建不同的操作栏。例如,一些页面会有一个标题和一个帮助按钮,而其他页面应该有一个设置按钮。

如何使用 Xamarin.Android 中的自定义导航渲染器来实现这一点?

自定义导航渲染器的示例代码:

[assembly: ExportRenderer(typeof(CustomNavigationPage), typeof(CustomNavigationPageRenderer))]
namespace MobileAppSamples.Droid.CustomRenderers
{
    public class CustomNavigationPageRenderer : NavigationRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<NavigationPage> e)
        {
            base.OnElementChanged(e);

            if (Element != null)
            {
                var actionBar = ((Activity)Context).ActionBar;

                Android.Widget.LinearLayout layout = new Android.Widget.LinearLayout(Context);
                layout.Orientation = Orientation.Horizontal;
                layout.WeightSum = 100;
                TextView title = new TextView(Context);
                title.Text = "sample";
                ViewGroup.LayoutParams textlp = new ViewGroup.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent);
                layout.AddView(title, textlp);
                actionBar.SetCustomView(layout, new ActionBar.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent));
                actionBar.SetDisplayOptions(ActionBarDisplayOptions.ShowCustom, ActionBarDisplayOptions.ShowCustom | ActionBarDisplayOptions.ShowHome );
            }

        }




    }
}

【问题讨论】:

    标签: android xamarin android-actionbar custom-controls navigationbar


    【解决方案1】:

    问题是您的获取活动。 测试这段代码:

    var bar = ((FormsApplicationActivity)Context).ActionBar;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-14
      • 2017-02-10
      • 1970-01-01
      • 2020-11-29
      • 1970-01-01
      • 2022-11-13
      • 1970-01-01
      相关资源
      最近更新 更多