Xamarin.forms 如何在xamarin中为android添加工具栏,窗体为ToolbarItem不适用于.droid?

Xamarin.forms 如何在xamarin中为android添加工具栏,窗体为ToolbarItem不适用于.droid?,xamarin.forms,uitoolbaritem,Xamarin.forms,Uitoolbaritem,我想在xamarin.forms中为我的移动应用程序提供一个工具栏。我在网上冲浪,了解了工具栏项目,但我认为它只适用于windows phone,不适用于android。在此问题上的任何帮助都将不胜感激。 附言:我需要一个在标签页工具栏也 以下是我的代码: //main page namespace eSewaXamarin { public class App:Application { public App () { MainPage = new Tabbe

我想在xamarin.forms中为我的移动应用程序提供一个工具栏。我在网上冲浪,了解了工具栏项目,但我认为它只适用于windows phone,不适用于android。在此问题上的任何帮助都将不胜感激。 附言:我需要一个在标签页工具栏也

以下是我的代码:

//main page

namespace eSewaXamarin
{

public class App:Application

{

public App ()

{   
        MainPage =  new TabbedPageClass ();
    }

    protected override void OnStart ()
    {
        // Handle when your app starts
    }

    protected override void OnSleep ()
    {
        // Handle when your app sleeps
    }

    protected override void OnResume ()
    {
        // Handle when your app resumes
    }


}
}

//tabbed page

namespace eSewaXamarin
{

public class TabbedPageClass: TabbedPage

{

public TabbedPageClass ()

{

    //this.SwipeEnabled = true;

    ToolbarItems.Add(new ToolbarItem("Click", null, () => {

    Console.WriteLine("Clicked");
            }));
            //this.Title = "eSewa";
            //TabbedPageClass tabbedPage=new TabbedPageClass();

            this.Children.Add (new MainMenu ());
            this.Children.Add (new QuickMenu ());
            this.Children.Add (new AboutPage ());


        }

    }
}

//about page

namespace eSewaXamarin
{

public class AboutPage:ContentPage

{

public AboutPage(){

Title="About";

this.BackgroundColor = Colors.lightGrey;


Padding = new Thickness (0,Device.OnPlatform(20, 0, 0),0,0);

            var listView = new ListView ();
            listView.ItemTemplate = new DataTemplate (typeof(AboutCell));
            listView.ItemsSource = AboutClass.getAboutText ();


            listView.RowHeight = 80;
            var fonePayIcon = new Image{ 
                Aspect = Aspect.AspectFit,


            };
            fonePayIcon.Source = ImageSource.FromFile ("footer_logo.png");
            this.Content = new ScrollView {
                Content = new StackLayout{
                    Children={listView,new StackLayout{
                            Padding=new Thickness(0,8,0,8),
                            BackgroundColor=Color.FromHex ("dfdfdf"),
                            VerticalOptions=LayoutOptions.EndAndExpand,
                            Children={fonePayIcon}
                        }
                    }
                }
            }; 



            listView.ItemSelected += (sender, e) => {
                if (e.SelectedItem != null) {

                    AboutClass aboutClass=(AboutClass)e.SelectedItem;
                    int id=aboutClass.id;
                    AppLog.showlog ("Selected item:::::" + aboutClass.id);
                    if(id==0){
                        Navigation.PushModalAsync (new NavigationPage(new Registration()));
                    }else if(id==1){
                        Navigation.PushModalAsync(new NavigationPage(new AbouteSewa()));
                    }else if(id==2){
                        Navigation.PushModalAsync(new AboutFonePay());
                    }else if(id==3){
                        Navigation.PushModalAsync(new AboutSecurityTips());
                    }else if(id==4){
                        Navigation.PushModalAsync(new AboutAppInfo());
                    }
                }
                ((ListView)sender).SelectedItem = null;

            };



        }
    }

}

//registration page


namespace eSewaXamarin
{

public class Registration: ContentPage

{

public Registration ()

{


    this.Title="Registration";

            ToolbarItems.Add(new ToolbarItem("Click", null, () => {
                Console.WriteLine("Clicked");
            }));

            this.BackgroundColor = Colors.lightGrey;
            var label = new Label {
                Text = Strings.eSewaRegistratinAbout,
                Style=Styles.LabelStyle
            };

            var registerButton=new Button{
                Text="Register",
                Style= Styles.buttonStyleGrey
            };

            var esewa_icon = new Image {
                Aspect = Aspect.AspectFit,

            };
            esewa_icon.Source = ImageSource.FromFile ("header_logo.png");

            Content = new StackLayout {

                Style = Styles.toolbarStyle,
                Children = {new StackLayout{
                        Style=Styles.stackLayoutStyleForAboutSection,
                        Children={label,registerButton}}
                }
            };

            registerButton.Clicked+=delegate{
                var SmsTask = MessagingPlugin.SmsMessenger;

                if (SmsTask.CanSendSms)


                SmsTask.SendSms("9801063628", "hello aqhtar ");
            };
        }
    }
}
  • 将此添加到您的
    页面
    构造函数

    ToolbarItems.Add(新建ToolbarItem(“单击”),null,()=>{
    Console.WriteLine(“单击”);
    }));
    
  • 确保您使用的是最新版本的Xamarin.Forms。它很好用

  • 主页
    包装在
    导航页面
    内:

    MainPage=newNavigationPage(newYourHomepage());
    
      • 将此添加到您的
        页面
        构造函数

        ToolbarItems.Add(新建ToolbarItem(“单击”),null,()=>{
        Console.WriteLine(“单击”);
        }));
        
      • 确保您使用的是最新版本的Xamarin.Forms。它很好用

      • 主页
        包装在
        导航页面
        内:

        MainPage=newNavigationPage(newYourHomepage());
        

      你想做什么?你有什么代码可以在Windows Phone上运行,但不能在Android上运行?您是使用XAML还是使用代码隐藏?请提供一些代码和您正在尝试做的更多细节,然后我们才能有效地帮助您:)我用代码编辑了这篇文章。请看一看。非常感谢。你想干什么?你有什么代码可以在Windows Phone上运行,但不能在Android上运行?您是使用XAML还是使用代码隐藏?请提供一些代码和您正在尝试做的更多细节,然后我们才能有效地帮助您:)我用代码编辑了这篇文章。请看一看。非常感谢。我以前也用过它,今天也试过了,但工具栏仍然没有显示出来。还有其他方法吗?你确定你有最新版本的Xamarin.Forms吗?你的主页是导航页面吗?我编辑了我的答案,实际上我有一个标签页作为主页。上面提到的内容页是从一个选项卡式页面调用的。将选项卡式页面作为主页是否与工具栏有关。关于xamarin.forms的版本,是的,我有最新版本的xamarin.forms。我已经在我的应用程序中用整个页面切换编辑了我的文章。我用我的项目运行了一个干净的构建,现在工作正常。我非常感谢你:)我以前也用过它,今天也试过了,但工具栏还是没有显示出来。还有其他方法吗?你确定你有最新版本的Xamarin.Forms吗?你的主页是导航页面吗?我编辑了我的答案,实际上我有一个标签页作为主页。上面提到的内容页是从一个选项卡式页面调用的。将选项卡式页面作为主页是否与工具栏有关。关于xamarin.forms的版本,是的,我有最新版本的xamarin.forms。我已经在我的应用程序中用整个页面切换编辑了我的文章。我用我的项目运行了一个干净的构建,现在工作正常。我非常感谢你:)