【发布时间】:2019-05-02 00:32:33
【问题描述】:
【问题讨论】:
-
这是一个 AlertDialog..go 一些 AlertDialog 示例,你会明白的
标签: android android-studio android-layout
【问题讨论】:
标签: android android-studio android-layout
我认为你想要做的是一个警告对话框......所以像这样
new AlertDialog.Builder(this)
.setTitle("Share using Wi-Fi Direct?")
.setCancelable(false)
.setMessage("You can only share folders using Wi-Fi Direct")
.setPositiveButton("SHARE VIA WI-FI DIRECT", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//do what you want here
}
})
.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//do what you want here
finish();
}
})
.create()
.show();
【讨论】:
试试这个
/* using sign out alert for app*/
private void dialogBox() {
android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(getActivity());
String titleText = "Share using Wi-Fi Direct?";
ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(Color.BLACK);
SpannableStringBuilder ssBuilder = new SpannableStringBuilder(titleText);
ssBuilder.setSpan(
foregroundColorSpan,
0,
titleText.length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
);
builder.setCancelable(false);
builder.setTitle(ssBuilder);
builder.setMessage("You can only share folders using Wi-Fi Direct");
builder.setPositiveButton("SHARE VIA WI-FI DIRECT", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// your code
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
// Create the alert dialog
android.support.v7.app.AlertDialog dialog = builder.create();
// Finally, display the alert dialog
dialog.show();
// Get the alert dialog buttons reference
Button positiveButton = dialog.getButton(android.support.v7.app.AlertDialog.BUTTON_POSITIVE);
Button negativeButton = dialog.getButton(AlertDialog.BUTTON_NEGATIVE);
// Change the alert dialog buttons text and background color
positiveButton.setTextColor(Color.parseColor("#00aff1"));
negativeButton.setTextColor(Color.parseColor("#00aff1"));
}
希望对你有帮助
【讨论】: