2012-02-19 13 views
5

Szukam sposobu na zmianę rozmiaru (aby nie dotykał krawędzi) EditText wewnątrz AlertDialog.Zmiana rozmiaru EditText wewnątrz AlertDialog

enter image description here

Mój przykładowy kod

AlertDialog.Builder alert = new AlertDialog.Builder(myActivity.this); 

alert.setTitle("Test"); 

EditText textBox = new EditText(myActivity.this); 
alert.setView(textBox); 

alert.setPositiveButton("OK", new DialogInterface.OnClickListener() { 
    public void onClick(DialogInterface dialog, int whichButton) { 
    // do nothing 
    } 
}); 

alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
    public void onClick(DialogInterface dialog, int whichButton) { 
// do nothing 
} 
}); 

alert.show(); 

Próbowałem rozwiązań przewidzianych tutaj bez powodzenia:

Odpowiedz

22

dodaj swój editext w liniowym layoucie i ustaw marginesy do tego układu. patrz poniżej:

AlertDialog.Builder alert = new AlertDialog.Builder(this); 

    alert.setTitle("Test"); 

    LinearLayout layout = new LinearLayout(this); 
    layout.setOrientation(LinearLayout.VERTICAL); 
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
     LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); 
    params.setMargins(20, 0, 30, 0); 

    EditText textBox = new EditText(myActivity.this); 
    layout.addView(textBox, params); 

    alert.setView(layout); 

    alert.setPositiveButton("OK", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int whichButton) { 
     // do nothing 
     } 
    }); 

    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int whichButton) { 
    // do nothing 
    } 
    }); 

    alert.show(); 
+0

Dziękuję za poświęcenie czasu, pomogło to umieścić właściwe elementy we właściwych miejscach. – ThePaul