如何实现一个确认(是/否)对话框preference?对话框、如何实现、preference

2023-09-04 08:17:07 作者:小众情人

我如何实现一个preference显示简单的是/否确认对话框?

How can I implement a Preference that displays a simple yes/no confirmation dialog?

有关示例,请参阅浏览器 - >设置 - >清除缓存

推荐答案

这是一个简单的警告对话框< /一>,费德里科给你一个网站,你可以看看的事情了。

That is a simple alert dialog, Federico gave you a site where you can look things up.

下面是如何构建一个警告对话框一个简单的例子。

Here is a short example of how an alert dialog can be built.

new AlertDialog.Builder(this)
.setTitle("Title")
.setMessage("Do you really want to whatever?")
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {

    public void onClick(DialogInterface dialog, int whichButton) {
        Toast.makeText(MainActivity.this, "Yaay", Toast.LENGTH_SHORT).show();
    }})
 .setNegativeButton(android.R.string.no, null).show();