1、Toast
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
//放在UI线程弹Toast
Toast.makeText(Setting.this, "正在更新请稍后", Toast.LENGTH_LONG).show();
}
});
2、弹出框
2.1默认样式
android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(AlertDialogActivity.this);
builder.setTitle("提示");
builder.setMessage("更新成功");
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(AlertDialogActivity.this, "确定了",Toast.LENGTH_SHORT).show();
}
});
builder.setNeutralButton("取消", null);
builder.show();
2.2单选
final String[] gender = new String[]{"java","android"};
android.support.v7.app.AlertDialog.Builder builder1=new android.support.v7.app.AlertDialog.Builder(AlertDialogActivity.this);
builder.setTitle("请选择");
builder.setItems(gender, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ToastUtil.showMsg(AlertDialogActivity.this,gender[which]);
}
});
builder.show();
android.support.v7.app.AlertDialog.Builder builder2=new android.support.v7.app.AlertDialog.Builder(AlertDialogActivity.this);
builder.setTitle("你最喜欢吃一下那种菜肴:");
final String[] dish =new String[]{"红烧牛肉","粉蒸排骨"};
builder.setSingleChoiceItems(dish, 1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ToastUtil.showMsg(AlertDialogActivity.this,dish[which]);
dialog.dismiss();
}
});
builder.setCancelable(false);
builder.show();
break;
2.3多选框
String[] dessert = new String[]{"抹茶千层","芒果拿破仑"};
boolean[] begin = new boolean[]{false,false};
android.support.v7.app.AlertDialog.Builder builder3=new android.support.v7.app.AlertDialog.Builder(AlertDialogActivity.this);
builder.setTitle("你吃过以下哪些甜点");
builder.setMultiChoiceItems(dessert, begin, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
}
});
builder.setPositiveButton("确认",null);
builder.setNegativeButton("取消",null);
builder.show();
break;
用的次数很多可以封装一下
Prompt.java
public class Promptextends MyApplication {
public static void Bill_headtk(final Bill_head ym,final String nr) {
new Thread(new Runnable() {
@Override
public void run() {
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
//放在UI线程弹Toast
AlertDialog.Builder builder=new AlertDialog.Builder(ym);
builder.setTitle("提示");
builder.setMessage(nr);
builder.setPositiveButton("确定",null);
builder.show();
}
});
}
}).start();
}
}
在Bill_head.java中调用
Prompt.Bill_headtk(Bill_head.this, "请输入");
其他类似