Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin 表单:onCreateOptions菜单方法不';在安卓7.0及更高版本上不会被呼叫_Xamarin_Xamarin.forms_Searchview_Android 7.0 Nougat - Fatal编程技术网

Xamarin 表单:onCreateOptions菜单方法不';在安卓7.0及更高版本上不会被呼叫

Xamarin 表单:onCreateOptions菜单方法不';在安卓7.0及更高版本上不会被呼叫,xamarin,xamarin.forms,searchview,android-7.0-nougat,Xamarin,Xamarin.forms,Searchview,Android 7.0 Nougat,我正在尝试在我的xamarin.forms Android项目的导航栏上显示搜索视图。但是搜索工具栏项目(搜索图标)在安卓7.0及以上版本上不可见,安卓6.0也可以正常工作 我已经按照链接为内容页编写了自定义呈现程序。它在安卓6.0上运行良好 在进一步搜索时,我得到了一个链接,如果我创建xamarin.android项目,这个链接可以正常工作,但在xamarin.forms上没有 这是我的主要活动代码: public class MainActivity : global::Xamarin.Fo

我正在尝试在我的xamarin.forms Android项目的导航栏上显示搜索视图。但是搜索工具栏项目(搜索图标)在安卓7.0及以上版本上不可见,安卓6.0也可以正常工作

我已经按照链接为内容页编写了自定义呈现程序。它在安卓6.0上运行良好

在进一步搜索时,我得到了一个链接,如果我创建xamarin.android项目,这个链接可以正常工作,但在xamarin.forms上没有

这是我的主要活动代码:

public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
    public static Android.Support.V7.Widget.Toolbar ToolBar { get; private set; }

    protected override void OnCreate(Bundle bundle)
    {
        TabLayoutResource = Resource.Layout.Tabbar;
        ToolbarResource = Resource.Layout.Toolbar;

        base.OnCreate(bundle);

        global::Xamarin.Forms.Forms.Init(this, bundle);

        LoadApplication(new App());
    }

    public override bool OnCreateOptionsMenu(IMenu menu)
    {
        ToolBar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
        return base.OnCreateOptionsMenu(menu);
    }
}
public class main活动:global::Xamarin.Forms.Platform.Android.formsappactivity
{
public static Android.Support.V7.Widget.Toolbar工具栏{get;private set;}
创建时受保护的覆盖无效(捆绑包)
{
TabLayoutResource=Resource.Layout.Tabbar;
ToolbarResource=Resource.Layout.Toolbar;
base.OnCreate(bundle);
全局::Xamarin.Forms.Forms.Init(这个,bundle);
加载应用程序(新应用程序());
}
公共覆盖布尔onCreateOptions菜单(IMenu菜单)
{
ToolBar=findviewbyd(Resource.Id.ToolBar);
返回base.onCreateOptions菜单(菜单);
}
}

不知道为什么此自定义方法在以后的版本中不再有效。但是在Xamarin表单中,有一种简单的方法可以在导航栏中显示。也许您可以尝试一下

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Samples.Views.MainPage" Title="Samples">
    <NavigationPage.TitleView>
        <SearchBar Text="input here"></SearchBar>
    </NavigationPage.TitleView>

    <StackLayout>
        <Button Text="SearchPage Sample" VerticalOptions="Center" Clicked="SearchPageSample_Clicked"/>
    </StackLayout>
</ContentPage>