- 浏览: 821856 次
- 性别:
- 来自: 北京、四川
文章分类
最新评论
-
sunbeamzheng:
总结的很好,好好看看。 拷贝问题确实很需要注意,特别是影不影响 ...
java深拷贝与浅拷贝 -
xmh8023:
...
获取POST数据的值 -
xmh8023:
我访问别的服务器怎么办?急求
获取POST数据的值 -
xmh8023:
String urlString="http://l ...
获取POST数据的值 -
lv12312:
Tomcat 7的老版本么?有bug的,https://iss ...
JMX问题
基本步骤如下:
1、继承Activity
2、在需要提示地方showDialog(id);
3、重载Activity的onCreateDialog(id)的方法
如:
4、运行android即可
5、有时在一个Activity中有多个不同样式的showDialog(id),则需要对onCreateDialog(id)方法重写成下面对方式:
switch (id)是对showDialog(id)中不同的ID选择不同的AlertDialog
View则可以对Dialog进行一些样式的修改
以下是android自带的apidemos下的比较完整弹出框例子
1、继承Activity
2、在需要提示地方showDialog(id);
3、重载Activity的onCreateDialog(id)的方法
如:
@Override protected Dialog onCreateDialog(int id) { return new AlertDialog.Builder(this) .setMessage("Please update your Settings.") .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //updatePreferences(); } }) .setNegativeButton( android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Noop. } }) .create(); }
4、运行android即可
5、有时在一个Activity中有多个不同样式的showDialog(id),则需要对onCreateDialog(id)方法重写成下面对方式:
@Override protected Dialog onCreateDialog(int id) { switch (id) { case CALL_ADDRESS: LayoutInflater factory = LayoutInflater.from(this); final View textBoxView = factory.inflate(R.layout.call_address_dialog, null); return new AlertDialog.Builder(this) .setTitle("title.") .setView(textBoxView) .setPositiveButton( android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { EditText textField = (EditText) (textBoxView.findViewById(R.id.calladdress_edit)); sipAddress = textField.getText().toString(); initiateCall(); } }) .setNegativeButton( android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Noop. } }) .create(); case UPDATE_SETTINGS_DIALOG: return new AlertDialog.Builder(this) .setMessage("Please update your Settings.") .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //updatePreferences(); } }) .setNegativeButton( android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Noop. } }) .create(); } return null; }
switch (id)是对showDialog(id)中不同的ID选择不同的AlertDialog
View则可以对Dialog进行一些样式的修改
以下是android自带的apidemos下的比较完整弹出框例子
/* * 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 android.widget.Toast; import android.database.Cursor; import android.provider.Contacts; 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 DIALOG_MULTIPLE_CHOICE_CURSOR = 8; 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_MULTIPLE_CHOICE_CURSOR: String[] projection = new String[] { Contacts.People._ID, Contacts.People.NAME, Contacts.People.SEND_TO_VOICEMAIL }; Cursor cursor = managedQuery(Contacts.People.CONTENT_URI, projection, null, null, null); return new AlertDialog.Builder(AlertDialogSamples.this) .setIcon(R.drawable.ic_popup_reminder) .setTitle(R.string.alert_dialog_multi_choice_cursor) .setMultiChoiceItems(cursor, Contacts.People.SEND_TO_VOICEMAIL, Contacts.People.NAME, new DialogInterface.OnMultiChoiceClickListener() { public void onClick(DialogInterface dialog, int whichButton, boolean isChecked) { Toast.makeText(AlertDialogSamples.this, "Readonly Demo Only - Data will not be updated", Toast.LENGTH_SHORT).show(); } }) .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 list of checkboxes, backed by a cursor */ Button checkBox2 = (Button) findViewById(R.id.checkbox_button2); checkBox2.setOnClickListener(new OnClickListener() { public void onClick(View v) { showDialog(DIALOG_MULTIPLE_CHOICE_CURSOR); } }); /* 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); } } }; } }
发表评论
-
AsyncTask
2011-04-10 12:15 1417here is a quick overview of how ... -
BroadcastReceive介绍
2011-04-09 10:03 1682转载:http://blog.csdn.net/Zengyan ... -
android 播放音频和视频
2011-03-31 15:47 1674摘自ApiDemo 1、播放音频 a.第一种方式 ... -
设置属性页面
2011-03-30 18:37 3444设置属性页面有两种方式 1、用xml完全的配置方式 2、完全使 ... -
android设置壁纸
2011-03-30 17:15 3378下面是Android的设置壁纸的一些代码(ApiDemo) ... -
文本中的值的保存与恢复
2011-03-30 16:29 1172这是android提供的ApiDemo里面的关于保存文本中值的 ... -
Intent-filter
2011-03-30 15:25 1993Intent-filter 个人理解就是为处理隐式Intent ... -
Some Standard Activity Actions
2011-03-30 14:25 1596摘自google android document Stand ... -
Intent学习
2011-03-30 14:03 1389参考:http://www.cnblogs.com/f ... -
android弹出框2(相当于通知)
2011-03-29 18:57 3351可以让其显示一会儿然后消失 也可以隔一段时间不断显示 第一种 ... -
android基本理解
2011-03-28 22:10 1018很久之前看过android的很多东西,由于工作忙以及其它一些事 ... -
android 中的url操作
2011-03-28 21:46 2792android 中的url操作步骤 1、获取HttpClien ...
相关推荐
android蓝牙使用,弹出框选择,获取名字和地址
android自定义弹出框的实现。 平时做项目时,感觉android自带的弹出框样式比较丑,很多应用都是自己做的弹出框,这里也试着自己做了一个。
Android:动画实现精美的弹出框(仿易信) 对应博文:http://blog.csdn.net/books1958/article/details/45219923
一个动态的弹出框,可以做动态提示什么的,自定义布局放入就可以。使用非常简单,并且做了性能上的优化,内存占用较小。但是发现个长时间弹出内存会升高,暂未发现原因
使用js alert函数弹出提示框,让界面看上去相对不友好,本代码实现了模拟android系统提示功能,弹出一个渐变的提示框提示信息,相当友好!
实现了Android的弹出框按钮点击接口监听器向C#事件的转换,原生android的listener变为mono android的event.
具体使用方法参考:http://blog.csdn.net/gaojinyu521748/article/details/37833305
做了一个android带小三角的弹出框,就是右上角有个小三角形,整体比较美观,代码精简没有多余,功能到位,具体大家下载下来自己看吧
BubbleLayout 弹出提示气泡
一块很简单的仿ios弹出框效果 包括底部弹出日期 地址等
Android开发时,有时候需要在底部弹出对话框,该项目实现了这一功能。 实现时,需要在styles.xml中添加自定义风格属性,对话框进入时和出去时分别加载不同的动画资源文件
第一次启动弹出提示框,当勾上checkbox后再次启动不再弹出提示框。
1、Toast Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { @Override public void run() { ...2、弹出框 2.1默认样式 android.support.v7.app.AlertDialog.Builder b
自定义简单弹出框Dialog辅助工具类 Alert实现弹出框加载XML或者视图VIEW
博客地址:http://blog.csdn.net/lowprofile_coding/article/details/49453455
弹出框样式的载入视图效果。项目地址:https://github.com/saiwu-bigkoo/Android-SVProgressHUD 效果图:如何使用使用超简单:SVProgressHUD.show(context);ok.另外,还有其他方式打开:比如,有关遮挡背景的:...
博客地址:http://blog.csdn.net/lowprofile_coding/article/details/49453455
使用kotlin的扩展函数实现,漂亮的对话框(弹出框),使用非常的简单,非常的好用!!!!!!使用kotlin的扩展函数实现,漂亮的对话框(弹出框),使用非常的简单,非常的好用!!!!!!
这是自己打包的一个aar,功能为在软件崩溃后弹出提示框提示重启或者退出,并且可以显示错误日志,帮助开发。调用方式applicaton下的onCreate中添加: CrashHanlder.getInstance().init(this);
项目中为了实现账号多设备登录的监听 一个账号在别的设备登录时在该设备上需要弹出对话框提示 故而用到全局对话框 方案一、 1、在开发中有时会用到全局弹出对话框但必须在manifest中申请权限: <uses android:name...