Visual Studio跨平台开发实战(4) - Xamarin Android基本控制项介绍
原文 Visual Studio跨平台开发实战(4) - Xamarin Android基本控制项介绍

public class ReadAsset : Activity
{
protected override void OnCreate (Bundle bundle) {
base.OnCreate (bundle);
InputStream input = Assets.Open ("my_asset.txt");}}

- LinearLayout: 主要的页面框架,以垂直或水平的方式排列页面上的对象,相当于Silverlight 中的stack pane
- @+id/[对象名称]: 告诉Android parser,为对象建立一个resource id
- @string/[名称]: 在String.xml中建立一个字符串资源,后续可供Resource类别存取

- 名称Hello对应到UI中Button的Text属性
- 名称ApplicationName对应到项目属性中的应用程序名称
- 名称Hello2为自行定义的字符串资源







SetContentView(Resource.Layout.TextView);
2. 从工具箱中拖拉1个Text(Small)及1个Plain Text对象到画面上并编辑Text的文字如下:





SetContentView(Resource.Layout.EditText);



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/textView1"/>
<ToggleButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/toggleButton1"
android:textOn="开"
android:textOff="关"
android:layout_marginBottom="6.7dp" />
<Switch
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textOn="开"
android:textOff="关"
android:id="@+id/Switch1"
android:layout_marginRight="225.3dp" />
</LinearLayout>
//载入页面
SetContentView(Resource.Layout.SwitchToggle);
//宣告并取得控件实体
ToggleButton toggle = FindViewById<ToggleButton>(Resource.Id.toggleButton1);
Switch _switch = FindViewById<Switch>(Resource.Id.Switch1);
TextView msg = FindViewById<TextView>(Resource.Id.textView1);
//处理Toggle Button的Click事件, 并将状态显示在TextView
toggle.Click+= (sender, e) => {
if (toggle.Checked) {
msg.Text = "目前Toggle Button的状态是\"开\"";}
else{
msg.Text = "目前Toggle Button的状态是\"关\"";};};
//处理Switch的Click事件, 并将状态显示在TextView
_switch.Click += (sender, e) => {
if (_switch.Checked) {
msg.Text = "目前Switch Button的状态是\"开\"";}
else{
msg.Text = "目前Switch Button的状态是\"关\"";};};
3. 执行项目并检视执行结果.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/textView1"/>
<Seekbar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/Seekbar1"
android:layout_marginRight="48.0dp" />
</LinearLayout>
//载入页面
SetContentView(Resource.Layout.SeekBar);
//宣告并取得页面上的控件
var msg = FindViewById<TextView>(Resource.Id.textView1);
var seekbar = FindViewById<SeekBar>(Resource.Id.seekBar1);
//将seekBar的最大值设定为100
seekbar.Max = 100;
//处理SeekBar的ProgressChanged事件,并将目前的大小(进度)透过TextView呈现
seekbar.ProgressChanged += (sender,e) => {
msg.Text = string.Format("目前Seekbar的大小为{0}",seekbar.Progress.ToString());
};
3. 执行项目并检视执行结果.

Visual Studio跨平台开发实战(4) - Xamarin Android基本控制项介绍的更多相关文章
- Visual Studio跨平台开发实战(2) - Xamarin.iOS基本控制项介绍
原文 Visual Studio跨平台开发实战(2) - Xamarin.iOS基本控制项介绍 前言 在上一篇文章中, 我们介绍了Xamarin 以及简单的HelloWorld范例, 这次我们针对iO ...
- Visual Studio跨平台开发(2):Xamarin.iOS基本控制项介绍
前言 在上一篇文章中, 我们介绍了Xamarin 以及简单的HelloWorld范例, 这次我们针对iOS的专案目录架构以及基本控制项进行说明. 包含UIButton,UISlider,UISwitc ...
- Visual Studio跨平台开发实战(5) - Xamarin Android多页面应用程式开发
原文 Visual Studio跨平台开发实战(5) - Xamarin Android多页面应用程式开发 前言 大部份的Android 都具有实体或虚拟的Back键. 因此在处理多页面应用程式时 ...
- Visual Studio跨平台开发实战(3) - Xamarin iOS多页面应用程式开发
原文 Visual Studio跨平台开发实战(3) - Xamarin iOS多页面应用程式开发 前言 在前一篇教学中, 我们学会如何使用Visual Studio 搭配Xcode 进行iOS基本控 ...
- Visual Studio跨平台开发(4):Xamarin Android控制项介绍
前言 不同于iOS, Xamarin 在Visual Studio中针对Android, 可以直接设计使用者界面. 在本篇教学文章中, 笔者会针对Android的专案目录结构以及基本控制项进行介绍, ...
- Visual Studio跨平台开发(5):Xamarin Android多页面应用开发
前言 大部份的Android 都具有实体或虚拟的Back键. 因此在处理多页面应用程序时, 与先前所介绍的iOS Navigation controller 比较起来会简单许多. 1. 开启Visua ...
- Visual Studio跨平台开发实战(1) - Hello Xamarin!
原文 Visual Studio跨平台开发实战(1) - Hello Xamarin! 前言 应用程式发展的脚步, 从来没有停过. 从早期的Windows 应用程式, 到网路时代的web 应用程式, ...
- Visual Studio跨平台开发(3):Xamarin iOS多页面应用开发
前言 在前一篇教学中, 我们学会如何使用Visual Studio 搭配Xcode进行iOS基本控制项的操作. 但都是属于单一画面的应用程式. 这次我们要来练习如何通过Navigation Contr ...
- Visual Studio跨平台开发(1):Hello Xamarin!
前言 应用程序发展的脚步, 从来没有停过. 从早期的Windows 应用程序, 到网络时代的web 应用程序, 再到近几年相当盛行的行动装置应用程序(Mobile Application), 身为C# ...
随机推荐
- OWAP Top 10
2013 Top 10 List A1-Injection Injection flaws, such as SQL, OS, and LDAP injection occur when untr ...
- oracle RAC搭建中的潜规则 该死的app
oracle RAC 安装目录必须是 ORACLE_BASE=/u01/app/grid ORACLE_HOME=/u01/app/11.2.0/grid 看着中间有个app,又没什么实际用处,就删掉 ...
- 排列-条件求和(Code)
static void Main(string[] args) { // Generate data int arraySize; int[] data; Random rnd; arraySize ...
- Swift - 使用网格(UICollectionView)的自定义布局实现复杂页面
网格UICollectionView除了使用流布局,还可以使用自定义布局.实现自定义布局需要继承UICollectionViewLayout,同时还要重载下面的三个方法: 1 2 3 4 5 6 7 ...
- opencv如何载入内存中的图像文件
其实很简单,cv::imdecode 支持 std::vector<uchar>的,只要把char* 转 std::vector<uchar>就行了.用 std::vector ...
- 关于java中的事件类型
java中的Date是为了证明:天才的程序员也会犯错: java中的Calendar是为了证明:普通的程序员也会犯错. ———————————————————— stackoverflow上大部分都推 ...
- 腾讯測试project师笔试面试记录
从3月29日參加腾讯笔试開始,開始了为期1周的腾讯之旅,尽管最后还是跪在了二面上,可是感觉收获非常多,至少明确了自己与向往的BAT公司的差距,明确了自己还是路漫漫其修远兮. 腾讯非常注 ...
- thinkPHP 模板的使用技巧(十三)
原文:thinkPHP 模板的使用技巧(十三) 模板的使用技巧:页面跳转 .模板包含.模板渲染.模板的继承 页面跳转 <a href='__URL__/index'>我要跳转到首页面,用这 ...
- android之JSON 进行网络数据交换
什么是JSON JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,易于阅读和编写,同一时候也易于机器解析和生成,很适合于server与client的交互. J ...
- 利用Node.js实现模拟Session验证的登陆
1.身份验证和用户登陆 在一般的Web应用上,假设要实现用户登陆,最经常使用,也是最简单的方法就是使用Session,主要的思路是在Session中保留一些用户身份信息,然后每次在Session中取, ...