`

各种单出窗口的代码

 
阅读更多
/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.android.apis.app;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.example.android.apis.R;

/**
* Example of how to use an {@link android.app.AlertDialog}.
* <h3>AlertDialogSamples</h3>

<p>This demonstrates the different ways the AlertDialog can be used.</p>

<h4>Demo</h4>
App/Dialog/Alert Dialog

<h4>Source files</h4>
* <table class="LinkTable">
*         <tr>
*             <td >src/com.example.android.apis/app/AlertDialogSamples.java</td>
*             <td >The Alert Dialog Samples implementation</td>
*         </tr>
*         <tr>
*             <td >/res/any/layout/alert_dialog.xml</td>
*             <td >Defines contents of the screen</td>
*         </tr>
* </table>
*/
public class AlertDialogSamples extends Activity {
    private static final int DIALOG_YES_NO_MESSAGE = 1;
    private static final int DIALOG_YES_NO_LONG_MESSAGE = 2;
    private static final int DIALOG_LIST = 3;
    private static final int DIALOG_PROGRESS = 4;
    private static final int DIALOG_SINGLE_CHOICE = 5;
    private static final int DIALOG_MULTIPLE_CHOICE = 6;
    private static final int DIALOG_TEXT_ENTRY = 7;

    private static final int MAX_PROGRESS = 100;
   
    private ProgressDialog mProgressDialog;
    private int mProgress;
    private Handler mProgressHandler;

    @Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {
        case DIALOG_YES_NO_MESSAGE:
            return new AlertDialog.Builder(AlertDialogSamples.this)
                .setIcon(R.drawable.alert_dialog_icon)
                .setTitle(R.string.alert_dialog_two_buttons_title)
                .setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        /* User clicked OK so do some stuff */
                    }
                })
                .setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        /* User clicked Cancel so do some stuff */
                    }
                })
                .create();
        case DIALOG_YES_NO_LONG_MESSAGE:
            return new AlertDialog.Builder(AlertDialogSamples.this)
                .setIcon(R.drawable.alert_dialog_icon)
                .setTitle(R.string.alert_dialog_two_buttons_msg)
                .setMessage(R.string.alert_dialog_two_buttons2_msg)
                .setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
   
                        /* User clicked OK so do some stuff */
                    }
                })
                .setNeutralButton(R.string.alert_dialog_something, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        /* User clicked Something so do some stuff */
                    }
                })
                .setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        /* User clicked Cancel so do some stuff */
                    }
                })
                .create();
        case DIALOG_LIST:
            return new AlertDialog.Builder(AlertDialogSamples.this)
                .setTitle(R.string.select_dialog)
                .setItems(R.array.select_dialog_items, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {

                        /* User clicked so do some stuff */
                        String[] items = getResources().getStringArray(R.array.select_dialog_items);
                        new AlertDialog.Builder(AlertDialogSamples.this)
                                .setMessage("You selected: " + which + " , " + items[which])
                                .show();
                    }
                })
                .create();
        case DIALOG_PROGRESS:
            mProgressDialog = new ProgressDialog(AlertDialogSamples.this);
            mProgressDialog.setIcon(R.drawable.alert_dialog_icon);
            mProgressDialog.setTitle(R.string.select_dialog);
            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            mProgressDialog.setMax(MAX_PROGRESS);
            mProgressDialog.setButton(getText(R.string.alert_dialog_hide), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {

                    /* User clicked Yes so do some stuff */
                }
            });
            mProgressDialog.setButton2(getText(R.string.alert_dialog_cancel), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {

                    /* User clicked No so do some stuff */
                }
            });
            return mProgressDialog;
        case DIALOG_SINGLE_CHOICE:
            return new AlertDialog.Builder(AlertDialogSamples.this)
                .setIcon(R.drawable.alert_dialog_icon)
                .setTitle(R.string.alert_dialog_single_choice)
                .setSingleChoiceItems(R.array.select_dialog_items2, 0, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        /* User clicked on a radio button do some stuff */
                    }
                })
                .setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        /* User clicked Yes so do some stuff */
                    }
                })
                .setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        /* User clicked No so do some stuff */
                    }
                })
               .create();
        case DIALOG_MULTIPLE_CHOICE:
            return new AlertDialog.Builder(AlertDialogSamples.this)
                .setIcon(R.drawable.ic_popup_reminder)
                .setTitle(R.string.alert_dialog_multi_choice)
                .setMultiChoiceItems(R.array.select_dialog_items3,
                        new boolean[]{false, true, false, true, false, false, false},
                        new DialogInterface.OnMultiChoiceClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton,
                                    boolean isChecked) {

                                /* User clicked on a check box do some stuff */
                            }
                        })
                .setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        /* User clicked Yes so do some stuff */
                    }
                })
                .setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        /* User clicked No so do some stuff */
                    }
                })
               .create();
        case DIALOG_TEXT_ENTRY:
            // This example shows how to add a custom layout to an AlertDialog
            LayoutInflater factory = LayoutInflater.from(this);
            final View textEntryView = factory.inflate(R.layout.alert_dialog_text_entry, null);
            return new AlertDialog.Builder(AlertDialogSamples.this)
                .setIcon(R.drawable.alert_dialog_icon)
                .setTitle(R.string.alert_dialog_text_entry)
                .setView(textEntryView)
                .setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
   
                        /* User clicked OK so do some stuff */
                    }
                })
                .setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        /* User clicked cancel so do some stuff */
                    }
                })
                .create();
        }
        return null;
    }

    /**
     * Initialization of the Activity after it is first created.  Must at least
     * call {@link android.app.Activity#setContentView(int)} to
     * describe what is to be displayed in the screen.
     */
    @Override
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.alert_dialog);
               
        /* Display a text message with yes/no buttons and handle each message as well as the cancel action */
        Button twoButtonsTitle = (Button) findViewById(R.id.two_buttons);
        twoButtonsTitle.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                showDialog(DIALOG_YES_NO_MESSAGE);
            }
        });
       
        /* Display a long text message with yes/no buttons and handle each message as well as the cancel action */
        Button twoButtons2Title = (Button) findViewById(R.id.two_buttons2);
        twoButtons2Title.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                showDialog(DIALOG_YES_NO_LONG_MESSAGE);
            }
        });
       
       
        /* Display a list of items */
        Button selectButton = (Button) findViewById(R.id.select_button);
        selectButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                showDialog(DIALOG_LIST);
            }
        });
       
        /* Display a custom progress bar */
        Button progressButton = (Button) findViewById(R.id.progress_button);
        progressButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                showDialog(DIALOG_PROGRESS);
                mProgress = 0;
                mProgressDialog.setProgress(0);
                mProgressHandler.sendEmptyMessage(0);
            }
        });
       
        /* Display a radio button group */
        Button radioButton = (Button) findViewById(R.id.radio_button);
        radioButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                showDialog(DIALOG_SINGLE_CHOICE);
            }
        });
       
        /* Display a list of checkboxes */
        Button checkBox = (Button) findViewById(R.id.checkbox_button);
        checkBox.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                showDialog(DIALOG_MULTIPLE_CHOICE);
            }
        });
       
        /* Display a text entry dialog */
        Button textEntry = (Button) findViewById(R.id.text_entry_button);
        textEntry.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                showDialog(DIALOG_TEXT_ENTRY);
            }
        });
       
        mProgressHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                if (mProgress >= MAX_PROGRESS) {
                    mProgressDialog.dismiss();
                } else {
                    mProgress++;
                    mProgressDialog.incrementProgressBy(1);
                    mProgressHandler.sendEmptyMessageDelayed(0, 100);
                }
            }
        };
    }
}
分享到:
评论
1 楼 白云天 2012-10-10  
/* 必须?setContentView之前调用全屏显示 */
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags
    (
      WindowManager.LayoutParams.FLAG_FULLSCREEN,
      WindowManager.LayoutParams.FLAG_FULLSCREEN
    );
   

相关推荐

    Java弹出窗口代码

    Java 弹出窗口代码详解 本文将详细介绍 Java 弹出窗口的代码实现,包括基本的弹出窗口代码和经过设置后的弹出窗口。通过本文,您将学习如何使用 Java 创建弹出窗口,如何设置弹出窗口的外观、尺寸大小和弹出位置。 ...

    超链接弹出独立新窗口代码

    ### 超链接弹出独立新窗口代码 在网页开发中,经常需要通过超链接打开新的页面或窗口,实现更好的用户体验。本篇文章将详细介绍如何利用HTML与JavaScript来实现在点击超链接时弹出一个独立的新窗口,而不是在浏览器...

    弹出窗口代码大全.txt

    ### 弹出窗口代码大全详解 #### 一、引言 在网页开发中,弹出窗口是一种常见的交互方式,它可以用于展示广告、提供额外信息或引导用户进行特定操作等。根据给定文件“弹出窗口代码大全.txt”的描述,本文将详细...

    弹出窗口代码大全.docx

    基本的弹出窗口代码非常简单,只需要使用JavaScript的`window.open()`函数即可。如下所示: ```html &lt;!-- window.open ('page.html'); --&gt; ``` 这段代码会在浏览器加载时打开名为`page.html`的新窗口。...

    弹出式窗口代码产生器

    弹出式窗口代码生成器是一种工具,用于帮助开发者快速创建和自定义在网页或应用程序中显示的弹出对话框。这种工具通常简化了编写JavaScript或HTML/CSS代码的过程,允许用户通过图形用户界面(GUI)设定窗口的大小、...

    点击文字弹出一个DIV层窗口代码

    点击文字弹出一个DIV层窗口代码,下载就能用

    Flex 弹出窗口代码

    在Flex编程中,"弹出窗口代码"是一个常见的需求,特别是在设计用户交互界面时,我们经常需要实现点击按钮后打开一个新的窗口或者对话框来展示更多信息或进行特定操作。本篇将详细讲解如何在Flex中创建一个点击按钮后...

    突破任何浏览器限制的弹出窗口代码

    突破任何浏览器限制的弹出窗口代码其实一切皆不是问题,最新的浏览器强制弹窗代码 让你的网站突破一切弹窗拦截,让所有的访客都可以看到你弹出的广告或页面让网站的广告收入大幅提升,本代码突破IE6,IE7,IE8,IE9 ...

    aspx页面弹出窗口代码大全

    在ASP.NET Web应用程序开发中,ASPx页面是基于.NET Framework的服务器控件,它提供了丰富的交互性...提供的文档"aspx页面弹出窗口代码大全.docx"应该包含了各种实现弹出窗口的示例代码和详细步骤,供开发者参考和学习。

    右下角弹出窗口实例代码

    本实例代码旨在实现一个兼容IE6+及Firefox浏览器的右下角滑出窗口,模仿腾讯QQ2009的样式。 首先,我们要理解这个实例的核心技术是JavaScript(JS),这是一种广泛使用的客户端脚本语言,用于增强网页的交互性。在...

    js css3九宫格弹出窗口代码.zip

    本项目“js css3九宫格弹出窗口代码”正是利用这两者,为用户提供了一个独特的九宫格布局,当用户点击某个单元格时,会弹出一个窗口展示详细信息,同时带有动画效果,提升了用户体验。 JavaScript是一种轻量级的...

    九种弹出窗口代码.doc

    【弹出窗口代码详解】 在网页开发中,有时我们需要实现一些交互效果,比如在用户进行特定操作时弹出一个新的窗口来展示相关信息或提供新的功能。本文将详细介绍九种不同的弹出窗口代码及其应用。 首先,最基本的弹...

    弹出窗口代码

    在探讨“弹出窗口代码”的知识点时,我们深入解析HTML与JavaScript如何协同工作,实现网页上弹出新窗口的功能。这一技术广泛应用于多种场景,如广告推送、信息提示或提供额外资源链接等。 ### 重要知识点一:HTML与...

    网页弹出窗口代码总汇(javascript)

    在《网页弹出窗口代码总汇(javascript)》这一主题中,我们将深入探讨如何利用JavaScript语言来实现网页中的弹出窗口功能,包括基本的弹出窗口代码、自定义窗口属性以及如何在不同场景下应用这些代码。 ### 基本的...

    JS关闭窗口弹出新窗口,关闭新窗口时,刷新父窗口,JS代码实现刷新网页,js实现弹出窗口代码收集集萃

    基本弹出窗口代码 要实现弹出窗口,只需在 HTML 文件中添加一段 JavaScript 代码即可。下面是一个基本的弹出窗口代码: ```html &lt;!-- window.open ('page.html') --&gt; ``` 这段代码使用 `window.open` 方法...

    9种js弹出动态窗口的 php代码

    "9种js弹出动态窗口的php代码"这个主题涵盖了利用这两种语言技术实现的各种弹窗功能。以下将详细介绍这些知识点: 1. **jQuery库**:jQuery是一个轻量级、高性能的JavaScript库,简化了HTML文档遍历、事件处理、...

    VB编程源代码 18弹出窗口时出现动画效果

    VB编程源代码 18弹出窗口时出现动画效果VB编程源代码 18弹出窗口时出现动画效果VB编程源代码 18弹出窗口时出现动画效果VB编程源代码 18弹出窗口时出现动画效果VB编程源代码 18弹出窗口时出现动画效果VB编程源代码 18...

    JAVA窗口代码

    JAVA窗口代码

    vc 各种窗口类型实现源代码

    在VC++编程环境中,"各种窗口类型实现源代码"涵盖了创建和管理不同类型的Windows窗口的实践知识。VC++,全称Visual C++,是Microsoft公司推出的一种集成开发环境,广泛用于编写Windows应用程序,特别是MFC...

Global site tag (gtag.js) - Google Analytics