高級控件(一)
1.Toast信息提示框
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(ToastImpl.this,
"短時間", Toast.LENGTH_SHORT).show();
}
});
2.對話框(Dislog)
1>警告框(AlertDialog)
Dialog ad=new AlertDialog.Builder(this)
.setTitle("警告是否刪除?") //設置標題
.setIcon(R.drawable.icon) //設置顯示圖片
.setMessage("確定要刪除信息嗎?") //設置內容
.create();
ad.show();
2>進度處理對話框
bt1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final ProgressDialog pDialog=ProgressDialog.show(Day09.this, "搜索", "正在加載中....");
new Thread(){
public void run(){
try {
Thread.sleep(3000);
} catch (Exception e) {
e.printStackTrace();
}finally{
pDialog.dismiss();
}
}
}.start();
pDialog.show();
}
});
3.>對話框操作事件
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Dialog ad=new AlertDialog.Builder(ToastImpl.this)
.setIcon(R.drawable.icon)
.setTitle("退出?")
.setMessage("是否退出")
.setNegativeButton("確定",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ToastImpl.this.finish();
}
})
.setPositiveButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setNeutralButton("查看詳情", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.create();
ad.show();
}
});
4.>對話框退出提示
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode==KeyEvent.KEYCODE_BACK){
Dialog dialog=new AlertDialog.Builder(ToastImpl.this)
.setIcon(R.drawable.sss)
.setTitle("退出")
.setMessage("是否退出")
.setNegativeButton("確認",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ToastImpl.this.finish();
}
}).create();
dialog.show();
return false;
}
return super.onKeyDown(keyCode, event);
}
高級控件(一)