装完mono之后,在弄monocross项目之前,先试了下直接用mono for Android开发Android应用。

1、创建一个mono for Android application。

右击项目,选择options,可以找到我们之前的AndroidManifest:

创建之后的目录架构如下:

弄过Android的一定不会陌生啦,assets:二进制资源文件;Resource:资源文件包;

其中的Activity1.cs就是我们的各个View的Controller了。

看里面的东西:Activity1.cs

using System;

using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace monoforandroidFirst
{
    [Activity (Label = "monoforandroidFirst", MainLauncher = true)]
    public class Activity1 : Activity
    {
        int count = 1;
        string text = null;

        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++);
                text = button.Text;
            };

            Button btn = FindViewById<Button>(Resource.Id.toView2Btn);
            btn.Click += btnHandle;
        }

        void btnHandle(object sender, EventArgs e){

            // 创建 Intent 并传递用户输入的信息
            var intent = new Intent(this,typeof(Activity2));
            intent.PutExtra("btn clicks","had click "+text+"times!");
            // 启动第二个 Activity
            this.StartActivity(intent);
        }
    }
}

更多相关文章

  1. jni读取assets资源文件
  2. Android项目实战--手机卫士01--启动界面
  3. 使用adb从android手机拉取文件到电脑
  4. Android Studio 集成 ShareSDK 如何 覆盖 文件夹
  5. Android 自动编译、打包生成apk文件 1 - 命令行方式
  6. 如何将文件路径从.java类文件传递到本机jni文件
  7. android MediaScanner 扫出来的ID3 MP3文件演唱者信息 乱码
  8. android-eclipse-phonegap 2..9以下(包含2.9)的项目配置
  9. android项目 之 记事本(14) ----- 手势缩放与拖拽图片

随机推荐

  1. Android官方开发文档Training系列课程中
  2. [Android(安卓)Training视频系列] 8.2 Ma
  3. Message Android的享元模式
  4. Android判断字符串中是否含字母、中文或
  5. Android(安卓)面试(四):Android(安卓)Servic
  6. Android支付宝沙箱环境使用教程
  7. Android(安卓)Studio 第五十五期 - Studi
  8. JAVA与Android(安卓)世界级序列化危机与
  9. Android(安卓)进阶
  10. 如何设置Android的AVD模拟器可以输入中文