Xamarin 支持使用C#开发基于Android、IOS、WindowsPhone应用开发,最大特色C#+跨平台,详细说明问度娘。html
安装 研究java
想体验研究的点击查看页面 Xamarin For Visual Studio 3.0.54.0 完整离线破解版 android
我也下载了研究下,破解有时候有问题,一登录就变成试用版,须要从新生成License,挺烦人,因而写了段批处理,放入记事本中另存为crack.bat执行,则可再次生成License。app
@Entitlements.bak为破解后生成的Entitlements的另存文件,登录后会被删除的,因此我改了名保存目录中 copy "C:\ProgramData\Mono for Android\License\Entitlements.bak" "C:\ProgramData\Mono for Android\License\Entitlements" /Y; copy "C:\ProgramData\MonoTouch\License\Entitlements.bak" "C:\ProgramData\MonoTouch\License\Entitlements" /Y; @下面2行分别为Android和IOS开发生成License "C:\Program Files\MSBuild\Xamarin\Android\mandroid.exe" -activate -activation-name=b4a -activation-phone=q -activation-company=b4a -activation-code=q -activation-email=q; "C:\Program Files\MSBuild\Xamarin\iOS\mtouch.exe" -activate -activation-name=b4a -activation-phone=q -activation-company=b4a -activation-code=q -activation-email=q;
本人电脑上装了vs2010+vs2013,Xamarin在vs2010比较正常,在vs2013 update2 上打开跨平台应用(Android+IOS)时vs2013会无响应死掉,没法正常使用。经过如下步骤能够正常工做ide
一、打开vs2013,工具--Xamarin Account 登录 -->变为试用版
二、vs中打开跨平台解决方案
三、工具--Xamarin Account 注销LogOut
四、执行bat:自动复制破解后的Entitlements,自动生成License
五、工具 -- Xamarin Account 弹出登录框 取消几回-->变为企业版工具
如今能够正常编码了,注意不要再登录了。布局
使用学习
代码结构ui
vs2013 vs Eclipse 其实差很少的this
Activity代码对比
using System; using Android.App; using Android.Content; using Android.Runtime; using Android.Views; using Android.Widget; using Android.OS; namespace HelloDroid { [Activity(Label = "HelloDroid", MainLauncher = true, Icon = "@drawable/icon")] public class MainActivity : 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++); }; } } }
package com.example.helloworld; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }
Layout布局文件对比
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Button android:id="@+id/MyButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/Hello" /> </LinearLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.helloworld.MainActivity" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> </RelativeLayout>
UI设计器
vs2013 支持拖控件
Eclipse
我的使用后小结
在Xamarin中开发Android应用与用java开发Android应用差很少,目录结构几乎同样,代码也差很少类似。Layout布局方式同样,控件与Eclipse中的控件也同样多。打包出的apk应用稍大(写了一个点击按钮计数程序app,支持Android 2.2+,apk大小为3.7M,因内部包含mono runtime因此较大)。
使用Xamarin开发的Android应用执行速度很快,一样在Android模拟器中执行C# 开发应用比Java Native 执行略快,在手机中执行与原生应用差异很小,三星Note2中比java开发的原生应用还快(引自国外文章)。有空写个程序认真比较下。
若是单纯开发Android应用,仍是建议用Java+Eclipse,毕竟是正统官方,开源类库多,帮助支持多,并且C#和java 原本就很类似,学习起来快而不难。Xamarin开发确定会存在某些局限和个别没法解决的问题,java开发就不会存在这些问题。
Xamarin 适用与跨平台开发(业务逻辑、数据访问部分可跨平台复用)、适用于会C#的不想学Java或Object C的、比较适用于IOS开发(毕竟从C#或Java到Object C跨度有点大)