Mono for Android: 利用mono for android开发的第一个程序
16lz
2021-01-22
装完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); } } }
更多相关文章
- jni读取assets资源文件
- Android项目实战--手机卫士01--启动界面
- 使用adb从android手机拉取文件到电脑
- Android Studio 集成 ShareSDK 如何 覆盖 文件夹
- Android 自动编译、打包生成apk文件 1 - 命令行方式
- 如何将文件路径从.java类文件传递到本机jni文件
- android MediaScanner 扫出来的ID3 MP3文件演唱者信息 乱码
- android-eclipse-phonegap 2..9以下(包含2.9)的项目配置
- android项目 之 记事本(14) ----- 手势缩放与拖拽图片