android 自定义对话框
来源:互联网 发布:在淘宝网开店的优势 编辑:程序博客网 时间:2024/05/16 02:04
说到对话框你肯定会想到AlertDialog.Builder。当然这次不是用AlertDialog.Builder来实现的!而是Dialog类
AlertDialog.Builder提供的方法有:
setTitle():给对话框设置title.
setIcon():给对话框设置图标。
setMessage():设置对话框的提示信息
setItems():设置对话框要显示的一个list,一般用于要显示几个命令时
setSingleChoiceItems():设置对话框显示一个单选的List
setMultiChoiceItems():用来设置对话框显示一系列的复选框。
setPositiveButton():给对话框添加”Yes”按钮。
setNegativeButton():给对话框添加”No”按钮。
那么在Dialog类怎样实现的呢?当然是layout啦,你可以自定义一个xml来布置你对话框
看看例子和源码吧
package com.hl;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
public class MyDialog extends Activity implements android.view.View.OnClickListener {
Button btn1=null;
Button btn2=null;
Button btn3=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn1=(Button)findViewById(R.id.b1);
btn2=(Button)findViewById(R.id.b2);
btn3=(Button)findViewById(R.id.b3);
btn1.setOnClickListener(this);
btn2.setOnClickListener(this);
btn3.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.b1:
break;
case R.id.b2:
case R.id.b3:
new MyDialogs(this).setDisplay();
break;
default:
}
}
class MyDialogs extends Dialog implements android.view.View.OnClickListener{
private Button b1;
private Window window=null;
public MyDialogs(Context context){
super(context);
}
public void setDisplay(){
setContentView(R.layout.dialog);//设置对话框的布局
b1=(Button)findViewById(R.id.clo);
b1.setOnClickListener(this);
setProperty();
setTitle("自定义对话框");//设定对话框的标题
show();//显示对话框
}
//要显示这个对话框,只要创建该类对象.然后调用该函数即可.
public void setProperty(){
window=getWindow();// 得到对话框的窗口.
WindowManager.LayoutParams wl = window.getAttributes();
wl.x =0;//这两句设置了对话框的位置.0为中间
wl.y =180;
wl.alpha=0.6f;//这句设置了对话框的透明度
wl.gravity=Gravity.BOTTOM;
window.setAttributes(wl);
}
@Override
public void onClick(View v) {
dismiss();//取消
}
}
}
- android中的对话框:自定义对话框
- Android Dialog( 自定义对话框)
- android 自定义对话框
- android自定义对话框
- Android自定义对话框
- android 自定义对话框
- Android自定义Dialog对话框
- android自定义大小对话框
- android自定义对话框
- Android自定义对话框
- android 自定义对话框
- android 自定义对话框
- android自定义对话框
- android 自定义对话框动画
- Android弹出自定义对话框
- android自定义对话框
- android 自定义对话框
- Android自定义对话框
- Web.config 配置文件
- Iphone之NSBundle
- pjsip sip开源协议栈
- Mysql的大小写敏感性
- 使用J-Flash 对ARM烧录HEX程序
- android 自定义对话框
- Linux多进程之fork()函数
- Ext_Ext.ViewPort
- ComboBox绑定两个字段
- 实时系统的基本特性
- 网络数据包收发流程(一):从驱动到协议栈
- jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中,及其相关
- MFC 程序入口和执行流程
- .NET Web应用程序安装包的制作经历