Hello Xamarin

来源:互联网 发布:淘宝优惠券设置淘口令 编辑:程序博客网 时间:2024/06/03 19:47

今天尝试了一下用Xamarin开发我的第一个Android程序。


1. 安装Xamarin Studio

安装Xamarin Studio之前首先要安装JDK、Android SDK。

目前我下载的Xamarin Studio版本是4.2.2,它需要1.6版本的SDK。虽然我电脑上已经安装了1.7版的JDK了,但还是要再安装JDK 1.6,好在它不影响我其余的Java应用程序。




2. 在 https://store.xamarin.com/account/register 申请试用帐号。


3. 使用此试用帐号,激活试用。



4. 打开Visual Studio / Xamarin Studio,创建一个Android应用程序



该项目模板自动生成的代码如下。注意,是C#的哟。

using System;using Android.App;using Android.Content;using Android.Runtime;using Android.Views;using Android.Widget;using Android.OS;namespace HelloMonoDroid{    [Activity(Label = "HelloMonoDroid", MainLauncher = true, Icon = "@drawable/icon")]    public class Activity1 : Activity    {        int count = 1;        protected override void OnCreate(Bundle bundle)        {            base.OnCreate(bundle);            // Set our view from the "main" layout resource            SetContentView(Resource.Layout.Main);            // Get our button from the layout resource,            // and attach an event to it            Button button = FindViewById<Button>(Resource.Id.MyButton);            button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };        }    }}

自动生成的界面如下:



直接在真机上调试。我新买的Android 4.2手机派上了用场。

运行正常。



0 0