弹出窗口

android

2013-10-09 16:49

1.

Toast.makeText(getBaseContext(), "TOAST", Toast.LENGTH_SHORT).show(); //简化版

                Toast t=Toast.makeText(getBaseContext(), "TOAST", Toast.LENGTH_SHORT);    
                t.setGravity(Gravity.CENTER, 0, 0);//位置
                LinearLayout loginForm = (LinearLayout)getLayoutInflater().inflate( R.layout.zdy, null);  //布局.
                t.setView(loginForm);   
                t.show();

2.


AlertDialog.Builder alertwin=new AlertDialog.Builder(MainActivity.this);

alertwin.setTitle("提示");

alertwin.setMessage("你确定要删除么");

alertwin.setIcon(R.drawable.s5);

alertwin.setNeutralButton("中断", new DialogInterface.OnClickListener() {

alertwin.setNegativeButton("取消",new DialogInterface.OnClickListener() {

alertwin.setPositiveButton("确定",new DialogInterface.OnClickListener() {

alertwin.create().show();

或者

AlertDialog atd=alertwin.create();

atd.show();


public CharSequence[] items={"上海","广州","深圳"};

AlertDialog.Builder at=new AlertDialog.Builder(MainActivity.this);

at.setTitle("选择");

//at.setMessage("你喜欢的城市");     //如果是列表就不要有内容的设定了

at.setItems(items, new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

    CharSequence sel = items[which];

    Toast.makeText(MainActivity.this, sel, 3).show();

}

});

AlertDialog atd=at.create();

atd.show();


4.

ProgressDialog prg = new ProgressDialog(MainActivity.this);

prg.setTitle("提示");

prg.setMessage("加载ing");

//prg.setCancelable(false);   按返回键不能退出。默认为true。

prg.show();

//隐藏 prg.dismiss();多线程关闭

//ProgressDialog.show(MainActivity.this, "加载中", "请稍后。。");  静态方法 后退不能关闭。。


5.

同上加入

prg.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);


6.日期选择

DatePickerDialog dprg= new DatePickerDialog(MainActivity.this, new OnDateSetListener() {

@Override

public void onDateSet(DatePicker view, int year, int monthOfYear,int dayOfMonth) {

Toast.makeText(getBaseContext(), year+"-"+monthOfYear+"-"+dayOfMonth, Toast.LENGTH_SHORT).show();//获取的值.

}

}, year, monthOfYear, dayOfMonth);  //默认年月日

dprg.show();

7.时间选择


TimePickerDialog tp=new TimePickerDialog(MainActivity.this, new TimePickerDialog.OnTimeSetListener() {

@Override

public void onTimeSet(TimePicker view, int hourOfDay, int minute) {

// TODO Auto-generated method stub

Toast.makeText(getBaseContext(), hourOfDay+"-"+minute, Toast.LENGTH_SHORT).show();

}

}, 11, 40, true);        //默认 11点40   最后一个参数  如果是false看下图。

tp.show();


8 自定义

Dialog dialog = new Dialog(MainActivity.this);

dialog.setTitle("自定义样式哦");

dialog.setContentView(R.layout.zdy);

dialog.show();

R.layout.zdy 布局自己设计。

AlertDialog.Builder alertwin=new AlertDialog.Builder(MainActivity.this);

alertwin.setTitle("提示");

alertwin.setMessage("你确定要删除么");

alertwin.setIcon(R.drawable.s5);

LinearLayout loginForm = (LinearLayout)getLayoutInflater().inflate( R.layout.zdy, null); // 设置显示的View对象    

 but100=(Button)loginForm.findViewById(R.id.button100);  //获取里面的按钮

but100.setOnClickListener(new OnClickListener() {        

@Override

public void onClick(View v) {

Toast.makeText(getBaseContext(), "乱了。。", Toast.LENGTH_SHORT).show();

}

});

alertwin.setView(loginForm);

alertwin.setNeutralButton("中断", new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

}

});

alertwin.setNegativeButton("取消",new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

}

});

alertwin.setPositiveButton("确定",new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

}

});

alertwin.create().show();