我的屏幕上有一个对话框。当我触摸屏幕时,对话框关闭。我希望对话框在外部接触时不要关闭。我的代码如下:
public class Dialogue extends Activity{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dialogue);
this.setFinishOnTouchOutside(false);
displayDialogue();
}
private void displayDialogue(){
final AlertDialog.Builder myDialogue = new AlertDialog.Builder(this);
myDialogue.setMessage("Please check your voice input output settings.It should be ON" );
TextView messageView = new TextView(this);
messageView.setGravity(Gravity.CENTER);
myDialogue.setView(messageView);
myDialogue.setPositiveButton("OK", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which) {
Intent i = new Intent(Dialogue.this, MainActivity.class);
startActivity(i);
finish();
}
});
AlertDialog dialog = myDialogue.create();
dialog.show();
}
最佳答案
可设置可取消(布尔可取消):
设置对话框是否可取消。Read More
myDialogue.setCancelable(false);