【发布时间】:2012-03-23 00:06:47
【问题描述】:
我在 Android 应用中有一个对话框,我不希望用户能够取消该对话框。使用.setCancelable(false) 禁用后退按钮,但按下搜索按钮仍会取消对话框。我看到this question 告诉我应该包括
public boolean onSearchRequested() {
return false;
}
但我仍然可以使用搜索按钮取消对话框。这是我的代码:
public class TestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
showDialog(0);
}
public boolean onSearchRequested() {
return false;
}
protected Dialog onCreateDialog(int id) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Message")
.setCancelable(false)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// nothing
}
});
return builder.create();
}
}
【问题讨论】:
-
这个问题似乎已经回答:stackoverflow.com/questions/2502443/…
标签: android