前面已经使用xamarin+visual studio配置了Android开发环境,这一次,来测试一下使用visual studio开发Android程序。听上去还是蛮有趣的。

首先使用想到新建一个Android 程序。新建 ->“Blank App(android)”,向导会自动创建所需要文件列表。最终创建效果如下:

这里需要注意到的是layout文件夹下有个main.axml,相当于使用eclipse创建时候的xml文件,这里,向布局文件内拖入一些空间,与Winform程序很类似,最终得到布局文件

如下

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"android:minWidth="25px"android:minHeight="25px"><Buttonandroid:text="Test Toast"android:layout_width="match_parent"android:layout_height="wrap_content"android:id="@+id/btnToast" /><TextViewandroid:text="Large Text"android:textAppearance="?android:attr/textAppearanceLarge"android:layout_width="match_parent"android:layout_height="wrap_content"android:id="@+id/textView1" /><TextViewandroid:text="Medium Text"android:textAppearance="?android:attr/textAppearanceMedium"android:layout_width="match_parent"android:layout_height="wrap_content"android:id="@+id/textView2" /><TextViewandroid:text="Small Text"android:textAppearance="?android:attr/textAppearanceSmall"android:layout_width="match_parent"android:layout_height="wrap_content"android:id="@+id/textView3" /><Switchandroid:layout_width="match_parent"android:layout_height="wrap_content"android:id="@+id/switch1" /><RadioGroupandroid:minWidth="25px"android:minHeight="25px"android:layout_width="match_parent"android:layout_height="wrap_content"android:id="@+id/radioGroup1"><RadioButtonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:checked="true"android:text="RadioButton"android:id="@+id/radioButton1" /><RadioButtonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="RadioButton"android:id="@+id/radioButton2" /><RadioButtonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="RadioButton"android:id="@+id/radioButton3" /></RadioGroup>
</LinearLayout>

这里使用线性布局,看上去与eclipse创建的布局语法无异。然后是针对于布局文件上的按钮进行编程,由于创建了activity,自动继承后,会重写

activity的oncreate方法,并设置main为主布局对象。与源生的Android编程不同,java中使用事件监听的方式,而C#使用委托的方法来实现点击事件。

java监听示例:

mPlayButton =(Button)v.findViewById(R.id.hellomoon_playButton);mPlayButton.setOnClickListener(new View.OnClickListener(){@Overridepublic void onClick(View v) {mPlayer.play(getActivity());}});

本次实例中,我们主要做一件事件,点击按钮,改变按钮的text,并弹出toast提示,最终的代码如下,已经测试通过:

using Android.App;
using Android.Widget;
using Android.OS;
using static Android.Views.View;namespace App1
{[Activity(Label = "TestApp", MainLauncher = true, Icon = "@drawable/icon")]public class MainActivity : Activity{Button btnToast;protected override void OnCreate(Bundle bundle){base.OnCreate(bundle);// Set our view from the "main" layout resourceSetContentView (Resource.Layout.Main);btnToast = (Button)FindViewById(Resource.Id.btnToast);btnToast.Click += BtnToast_Click;}private void BtnToast_Click(object sender, System.EventArgs e){string str = "Button Clicked";btnToast.Text = "Clicked!";Toast.MakeText(ApplicationContext, str, ToastLength.Long).Show();}}
}

xamarin开发Android程序示例相关推荐

  1. 【Xamarin开发 Android 系列 5】 Xamarin 的破解

    [Xamarin开发 Android 系列 5] Xamarin 的破解 原文:[Xamarin开发 Android 系列 5] Xamarin 的破解 有关这个话题,十分敏感,公司开发还是支持下商业 ...

  2. Eclipse开发Android程序如何在手机上运行

    http://www.cnblogs.com/plwang1990/archive/2011/07/04/2097757.htm android开发不论是在真机上调试还是最终发布到真机上都非常简单,过 ...

  3. 小米手机(HM1SW)高通开发android程序全过程

    小米手机(HM1SW)开发android程序全过程 修改历史: 2016年5月9日  --------  整理文档 a.增加了手机基本信息. b.增加360手机助手连接说明 2016年2月26日  - ...

  4. xamarin开发android收集的一些常用工具

    #xamarin开发android收集的一些常用工具 工欲善其事,必先利其器,从16年下半年开始做xamarin相关的开发,平时使用的一些工具和google插件给大家分享一下,都有下载地址,持续更新. ...

  5. 安卓 c 语言开发环境搭建,用C++语言开发Android程序 配置开发环境

    如果你是一个C++语言的死忠,你喜欢C++语言到了偏执的状态,如果不想学习Java语言,或者你很讨厌Java语言,如果你认为Java虚拟机的内存占用太多和执行低效.如果你过度关注Andoird程序的执 ...

  6. Go语言开发Android程序

    Go 语言开发 Android 程序 转自:http://studygolang.com/articles/9620 环境配置 安装 Go 1.5 以上版本,具体安装步骤见官网 https://gol ...

  7. xamarin Android 截屏,xamarin开发android收集的一些工具

    xamarin开发android收集的一些工具 工欲善其事,必先利其器,从16年下半年开始做xamarin相关的开发,平时使用的一些工具和google插件给大家分享一下,都有下载地址,持续更新. Vi ...

  8. C# 使用Xamarin开发Android应用程序

    微软移动跨平台开发(构建面向 Android.iOS 和 Windows phone应用): https://docs.microsoft.com/zh-cn/visualstudio/cross-p ...

  9. 【Xamarin开发 Android 系列 4】 Android 基础知识

    什么是Android? Android一词的本义指"机器人",同时也是Google于2007年11月5日宣布的基于Linux平台的开源手机操作系统的名称,该平台由操作系统.中间件. ...

最新文章

  1. Windows Phone 7 网络编程之留言板应用
  2. 复习笔记13 字符流与字节流
  3. DDPG-强化学习算法
  4. 李宏毅机器学习课程6~~~深度学习入门
  5. 短网址缩短和还原综合源码
  6. mysql 左连接 和全连接_mysql左连接,右连接,内连,全连
  7. 云计算成了“晕技术”就对了
  8. R语言︱ 数据库SQL-R连接与SQL语句执行(RODBC、sqldf包)
  9. 博一结束后的一些反思 -- 该如何平衡科研与生活
  10. JDK源码阅读-CharSequence接口
  11. 用ajax请求豆瓣api,结合豆瓣Api v2.0实现Jsonp跨域
  12. java fp-growth 算法包_java 实现fpGrowth算法
  13. 成功粉碎北信源监控程序vrvedp_m.exe ,vrvrf_c64.exe,svchost.exe,vrvrf_c.exe
  14. phpstudy快速搭建网站步骤(手把手教你搭建)
  15. 十年股市投资回顾与反思
  16. 什么是一维表 什么是二维表
  17. 进化计算——进化规划(EP)
  18. Xilinx UCF约束语法一
  19. ue4 unreal4 自定义网格 绘制自定义网格 绘制面 (Plus)
  20. tipask火车头采集器文章和提问发布模块|非免登录

热门文章

  1. 搜狗浏览器的页面静音
  2. 软件工程之PERT图和项目活动图考点(软考中级)
  3. Dreamweaver下载链接
  4. 【量化笔记】OBV指标交易策略
  5. 互联网金融产品的常见缺陷和预防
  6. 海马亚区微观结构及其与阿尔茨海默病血浆生物标志物的关系
  7. 关于生活励志的句子,生活是这样美好,活他一千辈子吧
  8. C#如何定义全局变量
  9. Map的keySet遍历
  10. 动态交互app界面设计原理指南