2012-02-19 15 views
5

के अंदर संपादन टेक्स्ट का आकार बदलना मैं AlertDialog के अंदर EditText का आकार बदलने के लिए एक तरीका ढूंढ रहा हूं (इसलिए यह किनारों को छूता नहीं है)।एक AlertDialog

enter image description here

मेरे नमूना कोड

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

मुझे कोई सफलता के साथ यहाँ प्रदान समाधान की कोशिश की है:

उत्तर

22

अपने संपादन को लाइनरलेआउट के अंदर जोड़ें और उस लेआउट में मार्जिन सेट करें। नीचे देखें:

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

समय लेने के लिए धन्यवाद, इससे सही जगहों पर सही टुकड़े लगाने में मदद मिली। – ThePaul

संबंधित मुद्दे