分类:C#、Android、VS2015;

创建日期:2016-02-08

在Android应用中,常用的对话框有:Toast、AlertDialog、ProgressDialog、时间选择对话框、日期选择对话框等。这一章主要介绍这些常用对话框的基本用法。

本章源程序共有4个示例,这些示例都在同一个项目中。

项目名:ch06demos

项目模板:Blank App(Android)

1、运行截图

主界面运行截图如下:

点击每行的示例项,即进入对应示例的页面。

2、主界面(Main.axml)

将Main.axml改为下面的代码:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent">    <ListView        android:minWidth="25px"        android:minHeight="25px"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:id="@+id/listView1" /></LinearLayout>

3、在AndroidManifest.xml文件中添加使用的主题

设置应用到所有页面的主题。

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="ch06demos.ch06demos" android:versionCode="1" android:versionName="1.0">  <uses-sdk android:minSdkVersion="16" />  <application android:label="ch06demos"    android:theme="@android:style/Theme.DeviceDefault.Light">  </application></manifest>

4、主界面对应的活动文件(MainActivity.cs)

本章示例全部完成后MainActivity.cs的代码如下:

using System.Collections.Generic;using Android.App;using Android.Widget;using Android.OS;using ch06demos.SrcActivity;namespace ch06demos{    [Activity(Label = "ch06demos", MainLauncher = true, Icon = "@drawable/icon")]    public class MainActivity : Activity    {        string[] items;        protected override void OnCreate(Bundle bundle)        {            base.OnCreate(bundle);            SetContentView(Resource.Layout.Main);            items = new string[]            {                "Demo01:Toast",                "Demo02:AlertDialog",                "Demo03:ProgressDialog",                "Demo04:DatePicker、TimePicker"            };            ListView listView1 = FindViewById<ListView>(Resource.Id.listView1);            listView1.Adapter = new ArrayAdapter<string>(this,                Android.Resource.Layout.SimpleListItem2, items);            listView1.ItemClick += (s, e) =>            {                int index = e.Position + 1;                switch (index)                {                    case 1:                        StartActivity(typeof(Demo01Toast));                        break;                    case 2:                        StartActivity(typeof(Demo02AlertDialog));                        break;                    case 3:                        StartActivity(typeof(Demo03ProgressDialog));                        break;                    case 4:                        StartActivity(typeof(Demo04DatePickerDialog));                        break;                }            };        }    }}

更多相关文章

  1. android 如何使用LaunchMode
  2. Android(安卓)startActivityForResult()的用法
  3. Qt on Android,输入法弹出后,界面无法自适应
  4. Eclipse中将一个android项目当做另外一个android项目的library
  5. Android(安卓)PreferenceActivity 学习笔记
  6. ICS 系统栏分析(一)
  7. Android调用系统自带的设置界面
  8. 【Android(安卓)界面效果22】Android的Tab与TabHost
  9. Intent妙用之编写自己的android主界面

随机推荐

  1. Android中MediaButtonReceiver广播监听器
  2. Android中各种onTouch事件
  3. Android修炼之道—时间测量
  4. Get the Android(安卓)SDK---获取Android
  5. php直播源码安卓自定义Dialog设置自动消
  6. Android(安卓)onMeasure、Measure、measu
  7. Delphi XE5 android toast
  8. Android(安卓)的网络编程(15)-Http JSon
  9. 问题小结(6)-listview滚动条相关
  10. [转] android 日期时间格式转换