1.界面

在Resources>layout>目录下的*.xml文件就是界面文件

appjavascript代码 app 代码_Click

 

 2.关联界面

接下来,通过将支持代码插入到 MainActivity 类中来添加代码以关联用户界面。

在 MainActivity 类中找到 OnCreate 方法,在其中添加关联按钮代码如下:

protected override void OnCreate(Bundle savedInstanceState)
        {/*这部分是程序自带的代码*/
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);            //通过ID绑定控件
            Button Task1 = FindViewById<Button>(Resource.Id.button1);
            Button Task2 = FindViewById<Button>(Resource.Id.button2);
            Button Task3 = FindViewById<Button>(Resource.Id.button3);
            Button Task4 = FindViewById<Button>(Resource.Id.button4);
            Button Stop= FindViewById<Button>(Resource.Id.button5);
            TextView Show= FindViewById<TextView>(Resource.Id.textView1);            //添加控件对应的事件
            Task1.Click += (sender, e) =>
            {
                Show.Text = "任务一进行中……";
            };
            Task2.Click += (sender, e) =>
            {
                Show.Text = "任务二进行中……";
            };
            Task3.Click += (sender, e) =>
            {
                Show.Text = "任务三进行中……";
            };
            Task4.Click += (sender, e) =>
            {
                Show.Text = "任务四进行中……";
            };
        }

现在就完成了一个简单的响应按钮事件的程序了。