[Android] Chapter 6 (1) Dialog Box--The main interface of this chapter's example
Category: C#, Android, VS2015; Creation date: 2016-02-08 In Android applications, commonly used dialog boxes include: Toast, AlertDialog, PRogressDialog, time selection dialog box, date selection dialog box, etc. This chapter mainly introduces the basic usage of these common dialog boxes. There are 4 examples of the source program in this chapter, and these examples are all in the same project
Category: C#, Android, VS2015;
Creation date: 2016-02-08
In Android applications, commonly used dialog boxes include: Toast, AlertDialog, PRogressDialog, time selection dialog box, date selection dialog box, etc. This chapter mainly introduces the basic usage of these common dialog boxes.
There are 4 examples of the source program in this chapter, and these examples are all in the same project.
Project name: ch06demos
Project template: Blank App(Android)
1. Running screenshots
The main interface operation screenshot is as follows:
Click on the example item in each row to enter the page of the corresponding example.
2. Main interface (Main.axml)
Change Main.axml to the following code:
<span style="color: #0000ff;"></span><span style="color: #ff00ff;">xml version="1.0" encoding="utf-8"</span><span style="color: #0000ff;">?></span> <span style="color: #0000ff;"><span style="color: #800000;">LinearLayout </span><span style="color: #ff0000;">xmlns:android</span><span style="color: #0000ff;">="http://schemas.android.com/apk/res/android"</span><span style="color: #ff0000;"> android:orientation</span><span style="color: #0000ff;">="vertical"</span><span style="color: #ff0000;"> android:layout_width</span><span style="color: #0000ff;">="fill_parent"</span><span style="color: #ff0000;"> android:layout_height</span><span style="color: #0000ff;">="fill_parent"</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"><span style="color: #800000;">ListView </span><span style="color: #ff0000;">android:minWidth</span><span style="color: #0000ff;">="25px"</span><span style="color: #ff0000;"> android:minHeight</span><span style="color: #0000ff;">="25px"</span><span style="color: #ff0000;"> android:layout_width</span><span style="color: #0000ff;">="match_parent"</span><span style="color: #ff0000;"> android:layout_height</span><span style="color: #0000ff;">="match_parent"</span><span style="color: #ff0000;"> android:id</span><span style="color: #0000ff;">="@+id/listView1"</span> <span style="color: #0000ff;">/></span> <span style="color: #0000ff;"></span><span style="color: #800000;">LinearLayout</span><span style="color: #0000ff;">></span></span></span>
3. Add the theme used in the AndroidManifest.xml file
Set a theme that applies to all pages.
<span style="color: #0000ff;"></span><span style="color: #ff00ff;">xml version="1.0" encoding="utf-8"</span><span style="color: #0000ff;">?></span> <span style="color: #0000ff;"><span style="color: #800000;">manifest </span><span style="color: #ff0000;">xmlns:android</span><span style="color: #0000ff;">="http://schemas.android.com/apk/res/android"</span><span style="color: #ff0000;"> package</span><span style="color: #0000ff;">="ch06demos.ch06demos"</span><span style="color: #ff0000;"> android:versionCode</span><span style="color: #0000ff;">="1"</span><span style="color: #ff0000;"> android:versionName</span><span style="color: #0000ff;">="1.0"</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"><span style="color: #800000;">uses-sdk </span><span style="color: #ff0000;">android:minSdkVersion</span><span style="color: #0000ff;">="16"</span> <span style="color: #0000ff;">/></span> <span style="color: #0000ff;"><span style="color: #800000;">application </span><span style="color: #ff0000;">android:label</span><span style="color: #0000ff;">="ch06demos"</span><span style="color: #ff0000;"> android:theme</span><span style="color: #0000ff;">="@android:style/Theme.DeviceDefault.Light"</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"></span><span style="color: #800000;">application</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"></span><span style="color: #800000;">manifest</span><span style="color: #0000ff;">></span></span></span></span>
4. Activity file corresponding to the main interface (MainActivity.cs)
After all the examples in this chapter are completed, the code of MainActivity.cs is as follows:
<span style="color: #0000ff;">using</span><span style="color: #000000;"> System.Collections.Generic; </span><span style="color: #0000ff;">using</span><span style="color: #000000;"> Android.App; </span><span style="color: #0000ff;">using</span><span style="color: #000000;"> Android.Widget; </span><span style="color: #0000ff;">using</span><span style="color: #000000;"> Android.OS; </span><span style="color: #0000ff;">using</span><span style="color: #000000;"> ch06demos.SrcActivity; </span><span style="color: #0000ff;">namespace</span><span style="color: #000000;"> ch06demos { [Activity(Label </span>= <span style="color: #800000;">"</span><span style="color: #800000;">ch06demos</span><span style="color: #800000;">"</span>, MainLauncher = <span style="color: #0000ff;">true</span>, Icon = <span style="color: #800000;">"</span><span style="color: #800000;">@drawable/icon</span><span style="color: #800000;">"</span><span style="color: #000000;">)] </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span><span style="color: #000000;"> MainActivity : Activity { </span><span style="color: #0000ff;">string</span><span style="color: #000000;">[] items; </span><span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> OnCreate(Bundle bundle) { </span><span style="color: #0000ff;">base</span><span style="color: #000000;">.OnCreate(bundle); SetContentView(Resource.Layout.Main); items </span>= <span style="color: #0000ff;">new</span> <span style="color: #0000ff;">string</span><span style="color: #000000;">[] { </span><span style="color: #800000;">"</span><span style="color: #800000;">Demo01:Toast</span><span style="color: #800000;">"</span><span style="color: #000000;">, </span><span style="color: #800000;">"</span><span style="color: #800000;">Demo02:AlertDialog</span><span style="color: #800000;">"</span><span style="color: #000000;">, </span><span style="color: #800000;">"</span><span style="color: #800000;">Demo03:ProgressDialog</span><span style="color: #800000;">"</span><span style="color: #000000;">, </span><span style="color: #800000;">"</span><span style="color: #800000;">Demo04:DatePicker、TimePicker</span><span style="color: #800000;">"</span><span style="color: #000000;"> }; ListView listView1 </span>= FindViewById<listview><span style="color: #000000;">(Resource.Id.listView1); listView1.Adapter </span>= <span style="color: #0000ff;">new</span> ArrayAdapterstring>(<span style="color: #0000ff;">this</span><span style="color: #000000;">, Android.Resource.Layout.SimpleListItem2, items); listView1.ItemClick </span>+= (s, e) =><span style="color: #000000;"> { </span><span style="color: #0000ff;">int</span> index = e.Position + <span style="color: #800080;">1</span><span style="color: #000000;">; </span><span style="color: #0000ff;">switch</span><span style="color: #000000;"> (index) { </span><span style="color: #0000ff;">case</span> <span style="color: #800080;">1</span><span style="color: #000000;">: StartActivity(</span><span style="color: #0000ff;">typeof</span><span style="color: #000000;">(Demo01Toast)); </span><span style="color: #0000ff;">break</span><span style="color: #000000;">; </span><span style="color: #0000ff;">case</span> <span style="color: #800080;">2</span><span style="color: #000000;">: StartActivity(</span><span style="color: #0000ff;">typeof</span><span style="color: #000000;">(Demo02AlertDialog)); </span><span style="color: #0000ff;">break</span><span style="color: #000000;">; </span><span style="color: #0000ff;">case</span> <span style="color: #800080;">3</span><span style="color: #000000;">: StartActivity(</span><span style="color: #0000ff;">typeof</span><span style="color: #000000;">(Demo03ProgressDialog)); </span><span style="color: #0000ff;">break</span><span style="color: #000000;">; </span><span style="color: #0000ff;">case</span> <span style="color: #800080;">4</span><span style="color: #000000;">: StartActivity(</span><span style="color: #0000ff;">typeof</span><span style="color: #000000;">(Demo04DatePickerDialog)); </span><span style="color: #0000ff;">break</span><span style="color: #000000;">; } }; } } }</span></listview>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In recent days, Ice Universe has been steadily revealing details about the Galaxy S25 Ultra, which is widely believed to be Samsung's next flagship smartphone. Among other things, the leaker claimed that Samsung only plans to bring one camera upgrade

OnLeaks has now partnered with Android Headlines to provide a first look at the Galaxy S25 Ultra, a few days after a failed attempt to generate upwards of $4,000 from his X (formerly Twitter) followers. For context, the render images embedded below h

Alongside announcing two new smartphones, TCL has also announced a new Android tablet called the NXTPAPER 14, and its massive screen size is one of its selling points. The NXTPAPER 14 features version 3.0 of TCL's signature brand of matte LCD panels

The Vivo Y300 Pro just got fully revealed, and it's one of the slimmest mid-range Android phones with a large battery. To be exact, the smartphone is only 7.69 mm thick but features a 6,500 mAh battery. This is the same capacity as the recently launc

In recent days, Ice Universe has been steadily revealing details about the Galaxy S25 Ultra, which is widely believed to be Samsung's next flagship smartphone. Among other things, the leaker claimed that Samsung only plans to bring one camera upgrade

Samsung has not offered any hints yet about when it will update its Fan Edition (FE) smartphone series. As it stands, the Galaxy S23 FE remains the company's most recent edition, having been presented at the start of October 2023. However, plenty of

Motorola has released countless devices this year, although only two of them are foldables. For context, while most of the world has received the pair as the Razr 50 and Razr 50 Ultra, Motorola offers them in North America as the Razr 2024 and Razr 2

The Redmi Note 14 Pro Plus is now official as a direct successor to last year'sRedmi Note 13 Pro Plus(curr. $375 on Amazon). As expected, the Redmi Note 14 Pro Plus heads up the Redmi Note 14 series alongside theRedmi Note 14and Redmi Note 14 Pro. Li
