Tengo una tarea para cambiar el ancho y alto de AlertDialog por xml, quiero que se convierta en estilo, para que pueda usarlo fácilmente. Y eso, también necesito cambiar el botón del estilo AlertDialog. ¿Puede decirme una forma de lograr el target.Thank que muy agradecidos. PS, me gustaría lograr mejor el objetivo por el cambio xml.Android: ¿Cómo puedo configurar el ancho y alto de AlertDialog, y el botón del estilo AlertDialog?
Android: ¿Cómo puedo configurar el ancho y alto de AlertDialog, y el botón del estilo AlertDialog?
Respuesta
Hay dos métodos 1) programáticamente 2) mediante el uso de diseño xml
1)=======>
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(layout);
builder.setTitle("Title");
alertDialog = builder.create();
alertDialog.show();
alertDialog.getWindow().setLayout(600, 400); //Controlling width and height.
(or)
alertDialog.show();
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(alertDialog.getWindow().getAttributes());
lp.width = 150;
lp.height = 500;
lp.x=-170;
lp.y=100;
alertDialog.getWindow().setAttributes(lp);
Si desea para mostrar el diseño que se mostrará como Alert dialog
ver this
2)========>
choose.xml
<TextView
android:id="@+id/img"
android:layout_width="wrap_content"
android:text="@string/choose"
android:textSize="25dp"
android:textColor="#fff"
android:layout_height="50dp"/>
<TableLayout android:id="@+id/table"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:orientation="vertical">
<TableRow
android:id="@+id/tr1"
android:orientation="horizontal"
android:layout_margin="10dp">
<ImageView
android:contentDescription="@string/phone"
android:src="@drawable/phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/phnText"
android:layout_width="wrap_content"
android:text="@string/phone"
android:gravity="left|center_vertical"
android:layout_marginLeft="10dp"
android:textSize="25dp"
android:textColor="#000"
android:layout_height="50dp"/>
</TableRow>
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#FF000000" />
<TableRow
android:id="@+id/tr2"
android:orientation="horizontal"
android:layout_margin="10dp">
<ImageView
android:contentDescription="@string/sms"
android:src="@drawable/sms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/smsText"
android:layout_width="wrap_content"
android:text="@string/sms"
android:gravity="left|center_vertical"
android:layout_marginLeft="10dp"
android:textSize="25dp"
android:textColor="#000"
android:layout_height="50dp"/>
</TableRow>
</TableLayout>
</LinearLayout>
pantalla esto como emergente, como a continuación como
private void showPopUp()
{
final AlertDialog.Builder helpBuilder = new AlertDialog.Builder(this);
helpBuilder.setTitle("");
LayoutInflater inflater = getLayoutInflater();
final View checkboxLayout = inflater.inflate(R.layout.choose, null);
helpBuilder.setView(checkboxLayout);
final AlertDialog helpDialog = helpBuilder.create();
helpDialog.show();
TableRow tablerowPhone = (TableRow)checkboxLayout.findViewById(R.id.tr1);
TableRow tablerowSms = (TableRow)checkboxLayout.findViewById(R.id.tr2);
tablerowPhone.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
helpDialog.dismiss();
Uri callUri = Uri.parse("tel:" + listview_array[4]);
Intent intent = new Intent(Intent.ACTION_CALL, callUri);
startActivity(intent);
}
});
tablerowSms.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
helpDialog.dismiss();
Uri smsUri = Uri.parse("sms:" + listview_array[4]);
Intent intent = new Intent(Intent.ACTION_VIEW, smsUri);
startActivity(intent);
}
});
}
llamada showPopUp()
este método en el que desea. por lo que se puede establecer la altura y la anchura de la distribución en el archivo xml
Muchas gracias. De esta manera puede hacerlo, pero quiero hacerlo por archivo xml. Porque quiero configurar el xml a mi aplicación. ¿Tienes una forma de hacerlo por archivo xml? Gracias una y otra vez. – oldfox3721
probar esto, esto funciona para mí,
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(layout);
builder.setTitle("Title");
alertDialog = builder.create();
alertDialog.getWindow().setLayout(600, 400); //Controlling width and height.
alertDialog.show();
- 1. Cambiar el color del botón en AlertDialog
- 2. Android AlertDialog Botón único
- 3. Cambiar el estilo de AlertDialog
- 4. Android: fuente de ancho fijo en AlertDialog
- 5. Android: AlertDialog personalizada
- 6. android: cómo alinear el mensaje en alertDialog?
- 7. Botones de estilo AlertDialog para una actividad
- 8. Android Solicitud de AlertDialog onBackPressed
- 9. ProgressDialog y AlertDialog causa ventana
- 10. ¿Cómo evitar que el botón de búsqueda cierre un AlertDialog?
- 11. Android - Custom AlertDialog Color de fondo
- 12. Establezca el alto y el ancho del botón como contenido de relleno y relleno principal
- 13. cómo cambiar la línea azul en el AlertDialog (tema Holo)
- 14. jQuery UI ancho y alto del diálogo en función del ancho y alto de la pantalla
- 15. Android EditText en AlertDialog parece demasiado amplio
- 16. Android: levanta AlertDialog desde el hilo de fondo
- 17. AlertDialog MultiChoiceItems Problemas del Oyente
- 18. Enfoque y teclado predeterminados para editar texto en Android AlertDialog
- 19. AlertDialog con selector de
- 20. Android - ¿Actualizar datos en un AlertDialog?
- 21. ListView en AlertDialog
- 22. Usando ArrayAdapter con AlertDialog y .setAdapter
- 23. Android: No se puede cambiar el texto aparece en AlertDialog
- 24. AlertDialog dentro de onClickListener
- 25. Tema de luz para AlertDialog?
- 26. Texto de entrada de AlertDialog
- 27. El método setCancelable (falso) de AlertDialog no funciona
- 28. Android AlertDialog cuadro WindowManager $ BadTokenException problema
- 29. Imágenes en AlertDialog botones
- 30. En Android, ¿cómo puedo establecer el alto y ancho de un elemento ListView?
Puede tener algo como esto http://stackoverflow.com/questions/1979369/ android-activity-as-a-dialog –
@ userIsAMonkey, muchas gracias, he pensado en usar Activity como un cuadro de diálogo, pero para mi tarea utilizar el cuadro de diálogo. porque hay muchos diálogos esperando para mostrar. Queremos tener un estilo fácil de mostrar. Gracias, alse. – oldfox3721