简体   繁体   English

按钮单击 => 在 xamarin android 中添加新标签

[英]button click => add new tab in xamarin android

我想知道您是否可以帮助我了解 Xamarin 教程中的编程语言 C#(按钮添加动态选项卡),我可以添加一个按钮来添加选项卡,例如 firefox 中的选项卡

You can add tabs dynamically but have no idea what you mean like in firefox.您可以动态添加选项卡,但不知道您在 Firefox 中的意思。 To add tabs dynamically you can do something like this:要动态添加选项卡,您可以执行以下操作:

public class MainActivity : Activity
{
    private int _count; 

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        SetContentView(Resource.Layout.Main);
        var button = FindViewById<Button>(Resource.Id.MyButton);

        ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;

        button.Click += AddTab;
    }

    private void AddTab(object sender, EventArgs e)
    {
        _count += 1;
        var tab = ActionBar.NewTab();
        tab.SetTag("Tab" + _count);
        tab.SetText("tab - " + _count);
        var temp = _count;
        tab.TabSelected +=
            (o, args) => { Toast.MakeText(this, "Tab " + temp + " selected!", ToastLength.Long).Show(); };
        ActionBar.AddTab(tab);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM