为了加强公司网站建设怎样制作微信小程序

当前位置: 首页 > news >正文

为了加强公司网站建设,怎样制作微信小程序,免费的网站开发平台,免费代理ip地址对话框对于应用是必不可少的一个组件#xff0c;在Android中也不例外。对话框对于一些提示重要信息#xff0c;或者询问用户采取决定是否采取的特殊动作等额外交互的内容很有帮助。本篇博客将讲解一下Android下对话框的使用。 一、Dialog的分类 Dialog对话框即一个小窗口在Android中也不例外。对话框对于一些提示重要信息或者询问用户采取决定是否采取的特殊动作等额外交互的内容很有帮助。本篇博客将讲解一下Android下对话框的使用。 一、Dialog的分类 Dialog对话框即一个小窗口并不会填满整个屏幕通常是以模态显示要求用户必须采取行动才能继续进行剩下的操作。   Android提供了丰富的对话框支持它提供了如下4中常用的对话框 1AlertDialog警告对话框使用最广泛功能最丰富的一个对话框。 2ProgressDialog进度条对话框只是对进度条进行了简单的封装。 3DatePickerDialog日期对话框。 4TimePickerDialog时间对话框。 所有的对话框都是直接或间接继承自Dialog类而AlterDialog直接继承自Dialog其他的几个类均继承自AlterDialog。 二、AlertDialog AlertDialog的构造方法全部是Protected的所以不能直接通过new一个AlertDialog来创建出一个AlertDialog。要创建一个AlertDialog就要用到AlertDialog.Builder中的create()方法。以下为基本方法及说明。 2.1 确定取消对话框 对话框中有2个按钮通过调用 setPositiveButton 方法和 setNegativeButton 方法 可以设置按钮的显示内容以及按钮的监听事件。 AlertDialog.Builder builder new AlertDialog.Builder(MainDialog.this); //创建AlertDialogbuilder.setIcon(R.drawable.icon); builder.setTitle(你确定要离开吗); builder.setPositiveButton(确定, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //这里添加点击确定后的逻辑 showDialog(你选择了确定); } }); builder.setNegativeButton(取消, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //这里添加点击确定后的逻辑 showDialog(你选择了取消); } }); builder.create().show(); span stylefont-size:14px;private void showDialog(String str) {
//用于onClick操作后监听内容信息下同AlertDialog.Builder(MainDialog.this) .setMessage(str) .show();
} /span 2.2 多个按钮信息框 AlertDialog.Builder builder new AlertDialog.Builder(MainDialog.this);
builder.setIcon(R.drawable.icon);
builder.setTitle(投票);
builder.setMessage(您认为什么样的内容能吸引您);
builder.setPositiveButton(有趣味的, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { showDialog(你选择了有趣味的); }
});
builder.setNeutralButton(有思想的, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { showDialog(你选择了有思想的); }
});
builder.setNegativeButton(主题强的, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { showDialog(你选择了主题强的); }
});
builder.create().show(); 2.3 列表框 final String[] mItems {item0,item1,itme2,item3,itme4,item5,item6}; //创建数组用于列表选择 AlertDialog.Builder builder new AlertDialog.Builder(MainDialog.this); builder.setTitle(列表选择框); builder.setItems(mItems, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { //点击后弹出窗口选择了第几项 showDialog(你选择的id为 which , mItems[which]); } }); builder.create().show(); 2.4 单项选择列表 int mSingleChoiceID -1; //用于记录单选中的IdAlertDialog.Builder builder new AlertDialog.Builder(MainDialog.this); mSingleChoiceID -1;
builder.setIcon(R.drawable.icon); builder.setTitle(单项选择); builder.setSingleChoiceItems(mItems, 0, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { mSingleChoiceID whichButton; showDialog(你选择的id为 whichButton , mItems[whichButton]); } }); builder.setPositiveButton(确定, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { if(mSingleChoiceID 0) { showDialog(你选择的是 mSingleChoiceID); } } }); builder.setNegativeButton(取消, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }); builder.create().show();   2.5 多项选择列表框 MultiChoiceID 用于记录多选选中的id号 存在ArrayList中选中后 add 进ArrayList取消选中后 remove 出ArrayList。 ArrayList IntegerMultiChoiceID new ArrayList Integer(); AlertDialog.Builder builder new AlertDialog.Builder(MainDialog.this); MultiChoiceID.clear();
builder.setIcon(R.drawable.icon); builder.setTitle(多项选择); builder.setMultiChoiceItems(mItems, new boolean[]{false, false, false, false, false, false, false}, new DialogInterface.OnMultiChoiceClickListener() { public void onClick(DialogInterface dialog, int whichButton, boolean isChecked) { if(isChecked) { MultiChoiceID.add(whichButton); showDialog(你选择的id为 whichButton , mItems[whichButton]); }else { MultiChoiceID.remove(whichButton); } } }); builder.setPositiveButton(确定, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String str ; int size MultiChoiceID.size(); for (int i 0 ;i size; i) { str mItems[MultiChoiceID.get(i)] , ; } showDialog(你选择的是 str); } }); builder.setNegativeButton(取消, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }); builder.create().show(); 2.6 进度条框 点击进度条框按钮后开启一个线程计算读取的进度。假设读取结束为 100Progress在小于100的时候一直在线程中做循环 直到读取结束后停止线程。 mProgressDialog new ProgressDialog(MainDialog.this); mProgressDialog.setIcon(R.drawable.icon); mProgressDialog.setTitle(进度条窗口); mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); mProgressDialog.setMax(MAX_PROGRESS); mProgressDialog.setButton(确定, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //这里添加点击后的逻辑 } }); mProgressDialog.setButton2(取消, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //这里添加点击后的逻辑 } }); mProgressDialog.show(); new Thread(this).start(); ic void run() {
int Progress 0;
while(Progress MAX_PROGRESS) {
try { Thread.sleep(100); Progress; mProgressDialog.incrementProgressBy(1);
} catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace();
} } 2.7 自定义布局 自定义布局在Android的开发中非常重要因为它能让开发者做出自己五彩缤纷的Activity而不用去使用系统枯燥的界面。比如我们在开发过程当中要通过介绍系统发送的一个广播弹出一个dialog但是dialog必需是基于activity才能呈现出来如果没有activity 的话程序就会崩溃。所以我们可以写一个自定义的 dialog 把它定义成一个activity这样我们收到一条打开dialog的广播后直接启动这个 activity  程序正常运行~~       注明下面这个例子只是写了自定义dialog 没有把它单独的写在一个activity中 如果需要的话 可以自己改一下。 AlertDialog.Builder builder new AlertDialog.Builder(MainDialog.this); LayoutInflater factory LayoutInflater.from(this); final View textEntryView factory.inflate(R.layout.test, null); builder.setIcon(R.drawable.icon); builder.setTitle(自定义输入框); builder.setView(textEntryView); builder.setPositiveButton(确定, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { EditText userName (EditText) textEntryView.findViewById(R.id.etUserName); EditText password (EditText) textEntryView.findViewById(R.id.etPassWord); showDialog(姓名 userName.getText().toString() 密码 password.getText().toString() ); } }); builder.setNegativeButton(取消, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }); builder.create().show(); RelativeLayout xmlns:androidhttp://schemas.android.com/apk/res/android android:layout_heightwrap_content android:layout_widthwrap_content android:orientationhorizontal android:idid/test
LinearLayout android:layout_heightwrap_content android:layout_widthwrap_content android:orientationhorizontal android:idid/dialogname TextView android:layout_heightwrap_content android:layout_widthwrap_content android:idid/tvUserName android:text姓名 / EditText android:layout_heightwrap_content android:layout_widthwrap_content android:idid/etUserName android:minWidth200dip/
/LinearLayout
LinearLayout android:layout_heightwrap_content android:layout_widthwrap_content android:orientationhorizontal android:idid/dialognum android:layout_belowid/dialogname TextView android:layout_heightwrap_content android:layout_widthwrap_content android:idid/tvPassWord android:text密码 / EditText android:layout_heightwrap_content android:layout_widthwrap_content android:idid/etPassWord android:minWidth200dip/
/LinearLayout
/RelativeLayout 三、ProgressDialog 有些时候只是需要提示用户等待比如在执行耗时操作等的时候可以使用进度对话框来显示一个进度信息提示用户等待这个时候可以使用ProgressDialog。ProgressDialog的使用方式大部分可以参见ProgressBar其实就是一个封装了ProgressBar的对话框。   ProgressDialog有两种显示方式一种是以一个滚动的环状图标可以显示一个标题和一段文本内容的等待对话框另外一种是带刻度的进度条和常规的进度条用法一致。两种样式通过ProgressDialog.setProgressStyle(int style)设置可以通过ProgressDialog的两个常量进行设置STYLE_HORIZONTAL刻度滚动STYLE_SPINNER图标滚动默认选项。   对于图标滚动可以使用两种方式实现一种是常规的调用构造函数再设置对应的属性另外一种是直接使用ProgressDialog的静态方法show()直接返回一个ProgressDialog对象并且调用show()方法。 // 第一种方法使用ProgressDialog构造函数progressDialog new ProgressDialog(MainActivity.this);progressDialog.setIcon(R.drawable.ic_launcher);progressDialog.setTitle(等待);progressDialog.setMessage(正在加载….);progressDialog.show();// 第二种方法使用静态的show方法progressDialogProgressDialog.show(MainActivity.this, 等待, 正在加载…., false, false);new Thread(new Runnable() {Overridepublic void run() {try {Thread.sleep(5000); } catch (Exception e) {e.printStackTrace();}finally{progressDialog.dismiss();} }}).start(); 转自http://www.cnblogs.com/afirefly/archive/2011/09/22/2185645.html        http://www.apkbus.com/android-138036-1-1.html?_dsigna2282f7e