第一次開通博客園的博客,有點小激動。廢話就不多說了,馬上開始。
1、安裝Visual Stuido2015(注意,在安裝的時候請不要勾選Android開發的相關組件,因為這樣的安裝速度極慢,10幾個小時都搞不定,因為我們要獨立安裝這些相關的組件)或者直接典型安裝。
2、安裝JDK7,雙擊這個圖標,然后狂按下一步就可以了。
3、安裝gtk-sharp,一樣雙擊打開狂按下一步。
4、安裝Android SDK(最好安裝在其他分區,這個東西后期會很大,因為要下載相關的SDK API,還要科學上網才能下載API,至於科學上網,你們懂的)
只要下載相關的API就好了,至於是否下載系統鏡像,你們隨意,不過速度會很慢。我們不需要使用自帶的模擬器,使用微軟VS的安卓模擬器就可以了。
就是這個:
回到SDK界面,把這些裝上(需要科學上網)
下面的那些也要勾上,除了有System Image這樣的不勾,其余的最后勾上,也可以按需勾。
5、解壓Andorid NDK,至於放在哪里,您隨意。
6、安裝Xamarin和Xamarin的VS插件。(收費的東西,大家都懂,但是不怕,購買這個的錢我們在清朝的時候就付清了)
(先安裝Xamarin Studio再安裝Xamarin For VS插件)
7、安裝VS安卓模擬器
上面的步驟基本已經完成了,下面我們就要打開VS,選擇“新建項目”,定位到Android程序模板那里,新建一個“空白的Android程序模板,點擊確定
雙擊Main.axml打開設計視圖
這個是我寫的,可以隨便在工具箱里拖點什么出來,也可以轉到源代碼視圖自己添加代碼
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:p1="http://schemas.android.com/apk/res/android" p1:orientation="vertical" p1:layout_width="match_parent" p1:layout_height="match_parent" p1:id="@+id/linearLayout1"> <TextView p1:layout_width="match_parent" p1:layout_height="64.6dp" p1:id="@+id/textView1" p1:textSize="22sp" p1:textColor="@android:color/holo_red_light" /> <Button p1:text="確定" p1:layout_width="match_parent" p1:layout_height="71.5dp" p1:id="@+id/button1" p1:background="@android:color/holo_red_light" p1:textSize="18sp" /> <TextView p1:text="The First Android Application Designed By LWJ" p1:layout_width="match_parent" p1:layout_height="85.0dp" p1:id="@+id/textView2" p1:textColor="@android:color/holo_blue_light" p1:textSize="22sp" p1:layout_marginTop="@android:dimen/app_icon_size" /> </LinearLayout>
這是上面視圖的代碼。
轉到MainActivity.cs,編寫代碼(我所編寫的只是一個HelloWorld)
using Android.App; using Android.Widget; using Android.OS; namespace HelloAndroid { [Activity(Label = "HelloAndroid", 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.button1); TextView ts = FindViewById<TextView>(Resource.Id.textView1); button.Click += delegate { ts.Text = "Hello Android"; button.Text = string.Format("第{0}次點擊", count++); }; } } }
最后選擇模擬器,運行看看效果
運行起來了,siguoyi,大功告成!
PS:請大神勿噴。
附件騷后上傳