2013-06-26 54 views
2

我的屏幕上有对话框。当我触摸屏幕对话框关闭。我想对话框不应该关闭在外面touch.My代码下面给出: -如何使对话框在外部触摸时保持打开

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(); 
    } 
+1

集可取消为虚假 –

+0

@ user2493740有一个upvoting /标记答案的习惯解决了有用的后 – CRUSADER

回答

2

加入这一行

myDialogue.setCancelable(false); 

希望这有助于..

3

setCancelable(布尔取消): 设置对话框是否可取消。 Read More

myDialogue.setCancelable(false); 
+0

@ user2493740,很高兴提供帮助。请标记为已接受并提供有效答案,以便为将来的Google员工提供帮助。 :) –

1

inisde方法.setMessage()displayDialog(),添加下面一行:

myDialogue.setCancelable(false); 
+0

@ user2493740你是否找到解决方案? –

2

设置取消属性假

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.setCancelable(false); 

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(); 
} 
3

你只需要设置取消为false,这样当对话框外面的触摸将保持打开状态。在你的代码 试试这个:

myDialogue.setCancelable(false); 
1

您可能已经得到了这一点,但对于未来的人来说,这工作对我来说: 您可以覆盖外面倒是做的对话框上没什么如图这里https://stackoverflow.com/a/5831214

相关问题