本文整理汇总了Java中android.support.v7.app.AlertDialog.setCancelable方法的典型用法代码示例。如果您正苦于以下问题:Java AlertDialog.setCancelable方法的具体用法?Java AlertDialog.setCancelable怎么用?Java AlertDialog.setCancelable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.app.AlertDialog
的用法示例。
在下文中一共展示了AlertDialog.setCancelable方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: allow_write_sd
import android.support.v7.app.AlertDialog; //导入方法依赖的package包/类
private void allow_write_sd() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.write_access));
builder.setMessage(getString(R.string.write_access_message));
builder.setPositiveButton(getString(R.string.button_ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if (Build.VERSION.SDK_INT >= 23 && !checkPermission()) {
// If user hasn't allowed yet, request the permission.
requestPermission();
}
}
});
AlertDialog alert = builder.create();
alert.setCancelable(false);
if (!checkPermission()) {
// If user hasn't allowed yet, show requester dialog.
alert.show();
}
}
示例2: onInitialized
import android.support.v7.app.AlertDialog; //导入方法依赖的package包/类
@Override
public void onInitialized(MainPresenter presenter, MainViewState viewState) {
if (!presenter.isInitialized()) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.enter_key);
builder.setMessage(R.string.key_requirments_message);
EditText editText = new EditText(this);
editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(16)});
builder.setView(editText);
builder.setPositiveButton(R.string.apply, null);
AlertDialog dialog = builder.create();
dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(false);
dialog.show();
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(v -> {
if (editText.getText().length() == 16) {
String key = editText.getText().toString();
presenter.initializeWithKey(key);
presenter.getValues();
dialog.dismiss();
} else {
Toast.makeText(this, R.string.bad_key, Toast.LENGTH_LONG).show();
}
});
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) editText.getLayoutParams();
int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16f, getResources().getDisplayMetrics());
layoutParams.setMargins(margin, margin, margin, margin);
editText.requestLayout();
} else {
if (!viewState.isPrefsLoaded() && !presenter.isTaskRunning(MainPresenter.TASK_GET_RUNNING)) {
presenter.getValues();
}
}
}
示例3: onPrompt
import android.support.v7.app.AlertDialog; //导入方法依赖的package包/类
@Override
public void onPrompt(UpdateAgent agent) {
final UpdateInfo info = agent.getInfo();
String size = Formatter.formatShortFileSize(mContext, info.size);
String content = String.format("最新版本:%1$s\n新版本大小:%2$s\n\n更新内容\n%3$s", info.versionName, size, info.updateContent);
final AlertDialog dialog = new AlertDialog.Builder(mContext).create();
dialog.setTitle("应用更新");
dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(false);
float density = mContext.getResources().getDisplayMetrics().density;
TextView tv = new TextView(mContext);
tv.setMovementMethod(new ScrollingMovementMethod());
tv.setVerticalScrollBarEnabled(true);
tv.setTextSize(14);
tv.setMaxHeight((int) (250 * density));
dialog.setView(tv, (int) (25 * density), (int) (15 * density), (int) (25 * density), 0);
DialogInterface.OnClickListener listener = new OnPromptClick(agent, true);
if (info.isForce) {
tv.setText("您需要更新应用才能继续使用\n\n" + content);
dialog.setButton(DialogInterface.BUTTON_POSITIVE, "确定", listener);
} else {
tv.setText(content);
dialog.setButton(DialogInterface.BUTTON_POSITIVE, "立即更新", listener);
dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "以后再说", listener);
if (info.isIgnorable) {
dialog.setButton(DialogInterface.BUTTON_NEUTRAL, "忽略该版", listener);
}
}
dialog.show();
}
示例4: onOptionsItemSelected
import android.support.v7.app.AlertDialog; //导入方法依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.about) {
final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle(getString(R.string.about_title));
ImageView iv = new ImageView(this);
int p = G.dpToPx(this, 10);
iv.setPadding(p, G.dpToPx(this, 20), p, p);
iv.setImageDrawable(logo);
iv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
visitWeb();
alertDialog.hide();
}
});
alertDialog.setView(iv);
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.visit_web), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
visitWeb();
}
});
alertDialog.setCancelable(true);
alertDialog.show();
return true;
}
return super.onOptionsItemSelected(item);
}
示例5: prompt
import android.support.v7.app.AlertDialog; //导入方法依赖的package包/类
@Override
public void prompt(IUpdateAgent agent) {
if (mContext instanceof Activity && ((Activity) mContext).isFinishing()) {
return;
}
final UpdateInfo info = agent.getInfo();
String size = Formatter.formatShortFileSize(mContext, info.size);
String content = String.format("最新版本:%1$s\n新版本大小:%2$s\n\n更新内容\n%3$s", info.versionName, size, info.updateContent);
final AlertDialog dialog = new AlertDialog.Builder(mContext).create();
dialog.setTitle("应用更新");
dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(false);
float density = mContext.getResources().getDisplayMetrics().density;
TextView tv = new TextView(mContext);
tv.setMovementMethod(new ScrollingMovementMethod());
tv.setVerticalScrollBarEnabled(true);
tv.setTextSize(14);
tv.setMaxHeight((int) (250 * density));
dialog.setView(tv, (int) (25 * density), (int) (15 * density), (int) (25 * density), 0);
DialogInterface.OnClickListener listener = new DefaultPromptClickListener(agent, true);
if (info.isForce) {
tv.setText("您需要更新应用才能继续使用\n\n" + content);
dialog.setButton(DialogInterface.BUTTON_POSITIVE, "确定", listener);
} else {
tv.setText(content);
dialog.setButton(DialogInterface.BUTTON_POSITIVE, "立即更新", listener);
dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "以后再说", listener);
if (info.isIgnorable) {
dialog.setButton(DialogInterface.BUTTON_NEUTRAL, "忽略该版", listener);
}
}
dialog.show();
}