2013-06-26 95 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

相關問題