Maison php教程 php手册 【Android】第6章(1)对话框--本章示例主界面

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

Jul 06, 2016 pm 01:30 PM
and android 分类 对话框 界面 示例

分类:C#、Android、VS2015; 创建日期:2016-02-08 在Android应用中,常用的对话框有:Toast、AlertDialog、PRogressDialog、时间选择对话框、日期选择对话框等。这一章主要介绍这些常用对话框的基本用法。 本章源程序共有4个示例,这些示例都在同一个项目

分类:C#、Android、VS2015;

创建日期:2016-02-08

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

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

项目名:ch06demos

项目模板:Blank App(Android)

1、运行截图

主界面运行截图如下:

image

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

2、主界面(Main.axml)

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

<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>
Copier après la connexion

 

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

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

<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>
Copier après la connexion

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

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

<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>
Copier après la connexion

Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn

Outils d'IA chauds

Undresser.AI Undress

Undresser.AI Undress

Application basée sur l'IA pour créer des photos de nu réalistes

AI Clothes Remover

AI Clothes Remover

Outil d'IA en ligne pour supprimer les vêtements des photos.

Undress AI Tool

Undress AI Tool

Images de déshabillage gratuites

Clothoff.io

Clothoff.io

Dissolvant de vêtements AI

AI Hentai Generator

AI Hentai Generator

Générez AI Hentai gratuitement.

Article chaud

R.E.P.O. Crystals d'énergie expliqués et ce qu'ils font (cristal jaune)
3 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Meilleurs paramètres graphiques
3 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Comment réparer l'audio si vous n'entendez personne
3 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: Comment déverrouiller tout dans Myrise
4 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌

Outils chauds

Bloc-notes++7.3.1

Bloc-notes++7.3.1

Éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise

SublimeText3 version chinoise

Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1

Envoyer Studio 13.0.1

Puissant environnement de développement intégré PHP

Dreamweaver CS6

Dreamweaver CS6

Outils de développement Web visuel

SublimeText3 version Mac

SublimeText3 version Mac

Logiciel d'édition de code au niveau de Dieu (SublimeText3)

Un nouveau rapport fournit une évaluation accablante des rumeurs de mise à niveau des appareils photo des Samsung Galaxy S25, Galaxy S25 Plus et Galaxy S25 Ultra Un nouveau rapport fournit une évaluation accablante des rumeurs de mise à niveau des appareils photo des Samsung Galaxy S25, Galaxy S25 Plus et Galaxy S25 Ultra Sep 12, 2024 pm 12:23 PM

Ces derniers jours, Ice Universe n'a cessé de révéler des détails sur le Galaxy S25 Ultra, qui est largement considéré comme le prochain smartphone phare de Samsung. Entre autres choses, le fuyard a affirmé que Samsung prévoyait d'apporter une seule mise à niveau de l'appareil photo.

Le Samsung Galaxy S25 Ultra fuit dans les premières images de rendu avec des rumeurs de modifications de conception révélées Le Samsung Galaxy S25 Ultra fuit dans les premières images de rendu avec des rumeurs de modifications de conception révélées Sep 11, 2024 am 06:37 AM

OnLeaks s'est désormais associé à Android Headlines pour offrir un premier aperçu du Galaxy S25 Ultra, quelques jours après une tentative infructueuse de générer plus de 4 000 $ auprès de ses abonnés X (anciennement Twitter). Pour le contexte, les images de rendu intégrées ci-dessous h

IFA2024 | Le NXTPAPER 14 de TCL n'égalera pas la Galaxy Tab S10 Ultra en termes de performances, mais il lui correspond presque en taille IFA2024 | Le NXTPAPER 14 de TCL n'égalera pas la Galaxy Tab S10 Ultra en termes de performances, mais il lui correspond presque en taille Sep 07, 2024 am 06:35 AM

En plus d'annoncer deux nouveaux smartphones, TCL a également annoncé une nouvelle tablette Android appelée NXTPAPER 14, et sa taille d'écran massive est l'un de ses arguments de vente. Le NXTPAPER 14 est doté de la version 3.0 de la marque emblématique de panneaux LCD mats de TCL.

Un nouveau rapport fournit une évaluation accablante des rumeurs de mise à niveau des appareils photo des Samsung Galaxy S25, Galaxy S25 Plus et Galaxy S25 Ultra Un nouveau rapport fournit une évaluation accablante des rumeurs de mise à niveau des appareils photo des Samsung Galaxy S25, Galaxy S25 Plus et Galaxy S25 Ultra Sep 12, 2024 pm 12:22 PM

Ces derniers jours, Ice Universe n'a cessé de révéler des détails sur le Galaxy S25 Ultra, qui est largement considéré comme le prochain smartphone phare de Samsung. Entre autres choses, le fuyard a affirmé que Samsung prévoyait d'apporter une seule mise à niveau de l'appareil photo.

Vivo Y300 Pro contient une batterie de 6 500 mAh dans un boîtier mince de 7,69 mm Vivo Y300 Pro contient une batterie de 6 500 mAh dans un boîtier mince de 7,69 mm Sep 07, 2024 am 06:39 AM

Le Vivo Y300 Pro vient d'être entièrement dévoilé et c'est l'un des téléphones Android de milieu de gamme les plus fins avec une grande batterie. Pour être exact, le smartphone ne fait que 7,69 mm d'épaisseur mais dispose d'une batterie de 6 500 mAh. C'est la même capacité que le lancement récent

Le Samsung Galaxy S24 FE est annoncé pour un lancement moins cher que prévu en quatre couleurs et deux options de mémoire Le Samsung Galaxy S24 FE est annoncé pour un lancement moins cher que prévu en quatre couleurs et deux options de mémoire Sep 12, 2024 pm 09:21 PM

Samsung n'a pas encore donné d'indications sur la date à laquelle il mettrait à jour sa série de smartphones Fan Edition (FE). Dans l’état actuel des choses, le Galaxy S23 FE reste l’édition la plus récente de la société, ayant été présentée début octobre 2023. Cependant, de nombreux

Xiaomi Redmi Note 14 Pro Plus arrive en tant que premier smartphone Qualcomm Snapdragon 7s Gen 3 avec caméra Light Hunter 800 Xiaomi Redmi Note 14 Pro Plus arrive en tant que premier smartphone Qualcomm Snapdragon 7s Gen 3 avec caméra Light Hunter 800 Sep 27, 2024 am 06:23 AM

Le Redmi Note 14 Pro Plus est désormais officiel en tant que successeur direct du Redmi Note 13 Pro Plus de l'année dernière (375 $ sur Amazon). Comme prévu, le Redmi Note 14 Pro Plus est en tête de la série Redmi Note 14 aux côtés du Redmi Note 14 et du Redmi Note 14 Pro. Li

iQOO Z9 Turbo Plus : les réservations commencent pour le produit phare de la série potentiellement renforcée iQOO Z9 Turbo Plus : les réservations commencent pour le produit phare de la série potentiellement renforcée Sep 10, 2024 am 06:45 AM

La marque sœur de OnePlus, iQOO, a un cycle de produits 2023-4 qui pourrait être presque terminé ; néanmoins, la marque a déclaré qu'elle n'en avait pas encore fini avec sa série Z9. Sa variante Turbo+ finale, et peut-être la plus haut de gamme, vient d'être annoncée comme prévu. T

See all articles