2010-06-10 11 views

Respuesta

13

añadir primer lugar la adecuada importación a su actividad:

import android.widget.Button; 

cree un nuevo objeto de botón dentro del método onCreate:

Button myButton = new Button(this); 
myButton.setText("Press Me"); 

Por último agregar el botón a la disposición:

LinearLayout layout = (LinearLayout) findViewById(R.id.layout1); 
layout.addView(myButton); 
+0

¿Cómo puedo establecer su ancho en fill_parent? El método setWidth del botón solo acepta int. –

+0

excelente ... realmente gracias –

Cuestiones relacionadas