1

我有一个自定义警报对话框,我用这个创建:

XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/backgroundgeneral"
android:padding="10dp" <!-- editted -->
    android:orientation="vertical" >

    <TextView
        android:id="@+id/tvMensajeAceptarDialogo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:textColor="@color/negro" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:gravity="center"
        android:weightSum="1" >

        <Button
            android:id="@+id/btnAceptarDialogo"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/bt_rojo"
            android:gravity="bottom|center"
            android:shadowColor="#000000"
            android:shadowDx="0"
            android:shadowDy="-1"
            android:shadowRadius="0.1"
            android:text="Aceptar"
            android:textColor="@color/blanco"
            android:textSize="14sp"
            android:textStyle="bold" />
    </LinearLayout>

</LinearLayout>

爪哇:

alerta = new AlertDialog.Builder(ConfirmarVisita.this).create();
LayoutInflater layoutInflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.layoutdialogoaceptar, null);
TextView mensaje = (TextView) view.findViewById(R.id.tvMensajeAceptarDialogo);
mensaje.setText("Visita confirmada");
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.width = LayoutParams.MATCH_PARENT;
lp.height = LayoutParams.MATCH_PARENT;
alerta.getWindow().setAttributes(lp);

Button btnAceptar = (Button) view.findViewById(R.id.btnAceptarDialogo);
btnAceptar.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        alerta.dismiss();
        Intent detalleServicio = new Intent(Contexto, DetalleServicio.class);
        detalleServicio.putExtra("codigo_parcela_servicio", servicioRecogido);
        startActivity(detalleServicio);
     }
});
alerta.setView(view);              
alerta.show();

但是当它显示得太小时:

太小

我究竟做错了什么?我尝试将宽度和高度设置为 500dp,但结果相同。

问题2,如何去除白色边框?我认为这两个问题是相同的,但我不确定。

4

3 回答 3

3
Display dm = getWindowManager().getDefaultDisplay();
    final int width = dm.getWidth();
    final int height = dm.getHeight();
dialog.getWindow().setLayout(width, height/2);

你可以试试。

于 2012-10-12T00:55:33.617 回答
1

试试这样的警报对话框

AlertDialog.Builder builder = new AlertDialog.Builder(
                ContactList.this);

        builder.setCancelable(true);
        builder.setTitle("your title");

        builder.setInverseBackgroundForced(true);

        builder.setNegativeButton("No",
                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });

        builder.setPositiveButton("Yes",
                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {


                         //your stuffs
                    }
                });

        AlertDialog alert = builder.create();
        alert.show();

这可能会帮助你

于 2012-10-08T07:43:28.157 回答
0

尝试android:layout_height为 base 设置一些值LinearLayout

例如:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"

    <!-- right here -->
    android:layout_height="100dp"

    android:background="@drawable/backgroundgeneral"
    android:padding="10dp" <!-- editted -->
    android:orientation="vertical" >
于 2016-01-17T21:41:24.303 回答