C# 入門指南

MainActivity.cs

using Android.App;
using Android.OS;
using Android.Support.V7.App;
using Android.Runtime;
using Android.Widget;
using Android.Content;

namespace AndroidAppDemo
{
    [Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
    public class MainActivity : AppCompatActivity
    {
        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);

            Button nextButton = FindViewById<Button>(Resource.Id.Next);
            nextButton.Click += (sender, e) =>
            {
                StartActivity(new Intent(this, typeof(EncodeActivity)));
            };
        }
        
        public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
        {
            Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);

            base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
        }
    }
}

//《程式語言教學誌》的範例程式
// http://kaiching.org/
// 專案:AndroidAppDemo
// 檔名:MainActivity.cs
// 功能:Encrypt 的 Android App 類別
// 作者:張凱慶

回 C# 入門指南首頁
回 C# 教材首頁
回程式語言教材首頁