AlertDialog 快速範例
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new AlertDialog.Builder(this)
.setIcon(R.drawable.ic_launcher)
.setTitle("標題")
.setMessage("內容")
.setPositiveButton("正邊按鈕", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "按了正邊", Toast.LENGTH_SHORT).show();
}
})
.setNeutralButton("中間按鈕", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "按了中間", Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton("反邊按鈕", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "按了反邊", Toast.LENGTH_SHORT).show();
}
})
.show();
}
}