Reputation: 12316
I have a custom alert dialog, I create with this:
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>
Java:
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();
But when it show its too small:
What am I doing wrong? I try to set 500dp for width and height but I have the same result.
And question 2, how can I remove the white border? I think the 2 problems are the same but I'm not sure.
Upvotes: 1
Views: 2188
Reputation: 5837
Try to set android:layout_height
to some value for base LinearLayout
.
For example:
<?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" >
Upvotes: 0
Reputation: 25
Display dm = getWindowManager().getDefaultDisplay();
final int width = dm.getWidth();
final int height = dm.getHeight();
dialog.getWindow().setLayout(width, height/2);
You can try it.
Upvotes: 3
Reputation: 11951
try like this Alert Dialog Box
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();
This might help you
Upvotes: 1