下面列出了android.app.AlertDialog#setTitle ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Show dialog with rationale for required permissions
*
* @param activity calling activity which the AlertDialog is shown on (PermissionsActivity)
* @return the dialog that is shown
*/
private static AlertDialog showRequiredPermissionRationale(final Activity activity) {
final AlertDialog
alertDialog = new AlertDialog.Builder(activity).create();
alertDialog.setTitle(activity.getString(R.string.title_activity_permissions));
alertDialog.setMessage(activity.getString(R.string.initial_permissions_required));
alertDialog.setButton(android.support.v7.app.AlertDialog.BUTTON_NEUTRAL,
activity.getString(R.string.ask_me_again),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
requestRequiredPermissions(activity, true);
}
});
alertDialog.setCancelable(false);
alertDialog.show();
return alertDialog;
}
/**
* Function to display simple Alert Dialog
*
* @param context
* - application context
* @param title
* - alert dialog title
* @param message
* - alert message
* @param status
* - success/failure (used to set icon) - pass null if you don't
* want icon
* */
@SuppressWarnings("deprecation")
public void showAlertDialog(Context context, String title, String message, Boolean status) {
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
// Setting Dialog Title
alertDialog.setTitle(title);
// Setting Dialog Message
alertDialog.setMessage(message);
if (status != null)
// Setting alert dialog icon
alertDialog.setIcon((status) ? R.drawable.success : R.drawable.fail);
// Setting OK Button
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
// Showing Alert Message
alertDialog.show();
}
public static Dialog showAlert(CharSequence title, CharSequence message, Context context,
CharSequence positiveBtnText, CharSequence negativeBtnText, OnClickListener positiveListener,
OnClickListener negativeListener) {
final AlertDialog alert = new AlertDialog.Builder(context).create();
alert.setCancelable(false);
alert.setCanceledOnTouchOutside(false);
if (positiveListener != null && positiveBtnText != null) {
alert.setButton(AlertDialog.BUTTON_POSITIVE, positiveBtnText, positiveListener);
}
if (negativeListener != null && negativeBtnText != null) {
alert.setButton(AlertDialog.BUTTON_NEGATIVE, negativeBtnText, negativeListener);
}
alert.setTitle(title);
alert.setMessage(message);
alert.show();
return alert;
}
public static void commonAlertDialog(Context parent, String title, String message) {
AlertDialog alertDialog = new AlertDialog.Builder(parent, AlertDialog.THEME_HOLO_DARK).create();
alertDialog.setTitle(title);
alertDialog.setMessage(Html.fromHtml(message));
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}
);
alertDialog.show();
}
private void showProjectContextMenu() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
final ArrayList<String> labels = new ArrayList<String>();
labels.addAll(labelsInTaskbagAndText());
if (labels.size() == 0) {
onHelpClick();
return;
}
builder.setItems(labels.toArray(new String[0]), new OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int which) {
replaceTextAtSelection(labels.get(which) + " ");
}
});
// Create the AlertDialog
AlertDialog dialog = builder.create();
dialog.setTitle(R.string.addcontextproject);
dialog.show();
}
public static void oneButtonAlert(Activity activity,String message, String title, String buttonText, final Runnable callBack) {
Log.i(LOG_TAG, "One button alert " + message);
AlertDialog alertDialog = new AlertDialog.Builder(activity).create();
alertDialog.setTitle(title);
// prevents the user from escaping the dialog by hitting the Back button
alertDialog.setCancelable(false);
alertDialog.setMessage(stringToHTML(message));
alertDialog.setButton(DialogInterface.BUTTON_NEUTRAL,
buttonText, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if (callBack != null) {
callBack.run();
}
}});
alertDialog.show();
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity());
final AlertDialog scheduleDownloadDialog = dialogBuilder.create();
scheduleDownloadDialog.setTitle(getText(R.string.schDwnBtn));
scheduleDownloadDialog.setIcon(android.R.drawable.ic_dialog_alert);
scheduleDownloadDialog.setCancelable(false);
scheduleDownloadDialog.setMessage(getText(R.string.schDown_install));
scheduleDownloadDialog.setButton(Dialog.BUTTON_POSITIVE, getString(android.R.string.yes), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
if (callback!=null) callback.onOkClick();
}
});
scheduleDownloadDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.no), new Dialog.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
if (callback!=null) callback.onCancelClick();
}
});
return scheduleDownloadDialog;
}
public void questionsAnswer() {
AlertDialog dialog = new AlertDialog.Builder(this).create();
dialog.setTitle("帮助说明");
dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(true);
dialog.setMessage("1.不能卸载软件:在设置界面关闭“开启锁屏”选项后,即可正常卸载。\r\n" +
"2.屏幕截图没反应:部分手机在第一次屏幕截图时需要稍等片刻,弹出授权框后,点击允许即可。\r\n" +
"3.截图保存在哪里:截图保存在系统存储卡根目录RelaxFinger文件夹里面。\r\n" +
"4.避让软键盘无效:安卓7.0以下系统避让软键盘功能最好安装两个及以上输入法(包含系统自带输入法)。\r\n" +
"5.不能开机自启动:首先确保设置界面“开机启动”选项已开启,如果仍然不能启动,到系统设置->" +
"安全->应用程序许可中找到RelaxFinger,点击进去后打开自动运行开关即可。\r\n" +
"6.自定义主题不好看:在系统存储卡根目录找到RelaxFinger目录,将里面的DIY.png换成喜欢的图片" +
",确保新图片名称依然是DIY.png即可。\r\n" +
"7.若频繁需要重新激活,系统设置->安全->应用程序许可->RelaxFinger->启用自动运行," +
"部分国产手机->电池管理->受保护应用->启用悬浮助手,任务管理器中的一键清除也会杀掉悬浮助手," +
"可以在任务管理界面,给悬浮助手加上锁即可,手机不同加锁方法自行百度," +
"华为是任务管理器界面按住悬浮助手往下拉,MIUI好像是就有个锁,点一下就好了。\r\n" +
"8.临时移动模式:悬浮球会向上移动一段距离,可自由移动,点击退出临时移动模式。打开关闭输入法会自动"+
"进入和退出临时移动模式。\r\n"+
"9.显示消息通知:当接收到消息时,悬浮球会变成相应的APP图标,并晃动提示,点击打开消息,上滑忽略"+
"当前消息,下滑忽略所有消息。\r\n"+
"10.安卓6.0及以上系统出现叠加层解决方法:在系统设置->开发者选项->停用HW叠加层即可。");
dialog.show();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.about) {
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle(getString(R.string.app_name));
alertDialog.setIcon(android.R.drawable.ic_dialog_info);
alertDialog.setMessage("Developed by Basilis Charalampakis\n\n" +
"GitHub : http://github.com/charbgr\n" +
"Linkedin : http://linkedin.com/in/charalampakisbasilis/");
alertDialog.show();
return true;
}
return super.onOptionsItemSelected(item);
}
public static void showAlert(Context context, String alertTitle, String alertMessage) {
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
alertDialog.setTitle(alertTitle);
alertDialog.setMessage(alertMessage);
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialog.show();
}
@Override
public void showOpenErrorDialog(String reason) {
Resources res = getResources();
mAlertBuilder = new AlertDialog.Builder(this);
AlertDialog alert = mAlertBuilder.create();
alert.setCancelable(false);
alert.setTitle(String.format(res.getString(R.string.cannot_open_document_Reason), reason));
alert.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.dismiss),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
alert.show();
}
public void saveUser(String result) {
ResultOfEnroll resultOfEnroll = gson.fromJson(result, ResultOfEnroll.class);
Log.d(TAG, resultOfEnroll.result.user);
editor = sharedPreferences.edit();
editor.putString("BlockchainUserId",resultOfEnroll.result.user);
editor.apply();
sendToMongo(resultOfEnroll.result.user);
// send user id to registeree-api
// save the user name
AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
alertDialog.setTitle("Enrollment successful!");
alertDialog.setMessage("You have been enrolled to the blockchain network. Your User ID is:\n\n" + resultOfEnroll.result.user);
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "CONFIRM",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.show();
}
private void showOkAlert(final String title, final String detail)
{
AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();
alertDialog.setTitle(title);
alertDialog.setMessage(detail);
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which)
{
dialog.dismiss();
}
});
alertDialog.show();
}
/**
* 展示一个通用的弹出框UI
*
* @param context 展示弹出框的上下文环境
* @param title 警告的title信息
* @param text 警告信息
*/
public static void showAlert(Context context, String title, String text) {
AlertDialog alertDialog = new Builder(context).create();
alertDialog.setTitle(title);
alertDialog.setMessage(text);
alertDialog.setCanceledOnTouchOutside(true);
alertDialog.show();
}
public static void confirm(String message, Activity activity, Boolean cancelable, DialogInterface.OnClickListener listener) {
AlertDialog dialog = new AlertDialog.Builder(activity).create();
dialog.setTitle(activity.getString(R.string.title));
dialog.setMessage(message);
dialog.setButton(AlertDialog.BUTTON_POSITIVE, "Yes", listener);
dialog.setButton(AlertDialog.BUTTON_NEGATIVE, "NO", listener);
if(cancelable){dialog.setButton(AlertDialog.BUTTON_NEUTRAL, "Cancel",listener);}
dialog.show();
}
public void showAlertDialog(Context context, String title, String message,
Boolean status) {
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
alertDialog.setTitle(title);
alertDialog.setMessage(message);
if(status != null)
alertDialog.setIcon((status) ? R.drawable.success : R.drawable.fail);
alertDialog.setButton("Тийм", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialog.show();
}
public void preparePatchInfo(AlertDialog dialog, ContentListItem patch) {
dialog.setTitle(patch.toString(getResources()));
String patchInfo;
try {
patchInfo = getPatchInfo(patch);
} catch (Exception e) {
patchInfo = "Cannot show info: " + e.getStackTrace();
}
dialog.setMessage(patchInfo);
}
public void developerInfo() {
AlertDialog dialog = new AlertDialog.Builder(this).create();
dialog.setTitle("关于悬浮助手");
dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(true);
dialog.setMessage("版本:3.0.4.3\r\n作者:fg607\r\n邮箱:[email protected]");
dialog.show();
}
public void onPrepareDialog(int dialogId, Dialog dialog) {
switch (dialogId) {
case DIALOG_MANAGE_PATCH:
case DIALOG_MANAGE_PATCH_CURRENTLY_ENABLED:
case DIALOG_MANAGE_PATCH_CURRENTLY_DISABLED:
if (selectedPatchItem == null) {
break;
}
AlertDialog aDialog = (AlertDialog) dialog;
aDialog.setTitle(selectedPatchItem.toString(getResources()));
break;
case DIALOG_PATCH_INFO:
if (selectedPatchItem == null) {
break;
}
preparePatchInfo((AlertDialog) dialog, selectedPatchItem);
break;
case DIALOG_IMPORT_FROM_CLIPBOARD_CODE:
AlertDialog bDialog = (AlertDialog) dialog;
android.text.ClipboardManager cmgr = (android.text.ClipboardManager) this.getSystemService(Context.CLIPBOARD_SERVICE);
CharSequence cSequence = cmgr.getText();
((EditText) bDialog.findViewById(20130805)).setText(cSequence);
break;
case DIALOG_IMPORT_FROM_INTENT:
AlertDialog cDialog = (AlertDialog) dialog;
cDialog.setTitle(getIntent().getData().toString());
break;
default:
super.onPrepareDialog(dialogId, dialog);
}
}
private void warnNoSignatureSupport() {
AlertDialog dialog = mSignatureReportBuilder.create();
dialog.setTitle("App built with no signature support");
dialog.show();
}