【Android】第6章(1)对话框--本章示例主界面

王朝学院·作者佚名  2016-08-28
窄屏简体版  字體: 小  |  中  |  大  |  超大  

分类:C#、Android、VS2015;

创建日期:2016-02-08

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

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

项目名:ch06demos

项目模板:Blank App(Android)

1、运行截图

主界面运行截图如下:

[flash=500,400]http://s1.knowsky.com/20160211/0nj50lce5b552.png[/flash]

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

2、主界面(Main.axml)

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

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><ListViewandroid: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"?><manifestxmlns:android="http://schemas.android.com/apk/res/android"package="ch06demos.ch06demos"android:versionCode="1"android:versionName="1.0"><uses-sdkandroid:minSdkVersion="16"/><applicationandroid:label="ch06demos"android:theme="@android:style/Theme.DeviceDefault.Light"></application></manifest>

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

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

usingSystem.Collections.Generic;usingAndroid.App;usingAndroid.Widget;usingAndroid.OS;usingch06demos.SrcActivity;namespacech06demos

{

[Activity(Label="ch06demos", MainLauncher =true, Icon ="@drawable/icon")]publicclassMainActivity : Activity

{string[] items;protectedoverridevoidOnCreate(Bundle bundle)

{base.OnCreate(bundle);

SetContentView(Resource.Layout.Main);

items=newstring[]

{"Demo01:Toast","Demo02:AlertDialog","Demo03:ProgressDialog","Demo04:DatePicker、TimePicker"};

ListView listView1= FindViewById<ListView>(Resource.Id.listView1);

listView1.Adapter=newArrayAdapter<string>(this,

Android.Resource.Layout.SimpleListItem2, items);

listView1.ItemClick+= (s, e) =>{intindex = e.Position +1;switch(index)

{case1:

StartActivity(typeof(Demo01Toast));

break;case2:

StartActivity(typeof(Demo02AlertDialog));

break;case3:

StartActivity(typeof(Demo03ProgressDialog));

break;case4:

StartActivity(typeof(Demo04DatePickerDialog));

break;

}

};

}

}

}

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航