2014-05-04 26 views
0

我有一個函數可以創建一個對話框,其中包含標題,一些文本和底部的EditText。 它也有2個按鈕在底部。 但是,如果文本太長,對話框高度會增加,直到按鈕幾乎無法到達,儘管大文本的滾動條確實會出現,而不會顯示整個文本。Android - 對話框在屏幕高度延伸

以下是對話的圖像之前和大量的文字出現在身體後... The dialog at first

the dialog after a lot of text

這裏是我產卵的對話框:

AlertDialog.Builder dialogbuilder = new AlertDialog.Builder(MainProgram.currentActivity); 
dialogbuilder.setTitle("Title:"); 
final EditText input = new EditText(MainProgram.currentActivity); 
dialogbuilder.setView(input); 

dialogbuilder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { 
    public void onClick(DialogInterface dialog, int whichButton) { 

    } 
}); 

dialogbuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
    public void onClick(DialogInterface dialog, int whichButton) { 

    } 
}); 

dialogbuilder.create().show(); 

我怎樣才能解決這個問題(以編程方式)?

回答

0

您可以使用input.setMaxLines來設置最大行數。您必須在設置input作爲視圖前輸入此行。希望這對你有所幫助!

+0

@VladimirGazbarov如果這個答案對您有幫助,請檢查它是否有幫助。謝謝 – JCoder

+0

你的建議確實限制了editText對象的行數。問題在於對話的消息延伸... –