2012-10-08 26 views
1

我有一個自定義警告對話框中,我創建了這一點:Alertdialog太小

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

但是,當它顯示它太小了:

toosmall

我在做什麼錯了?我嘗試設置500dp的寬度和高度,但我有相同的結果。

問題2,我該如何去除白色邊框?我認爲這兩個問題是相同的,但我不確定。

+0

隨着填充工作正常,但我怎麼能去除lareatal,頂部和底部的白色邊緣? – colymore

回答

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

這可以幫助你

+0

大小它確定,但我不能刪除白色邊緣。 – colymore

+0

您是否嘗試過爲我編輯過的新代碼? – Syn3sthete

+0

有點你有相同的結果,但這隻會讓我在星系選項卡8.9或10.1 ..爲什麼? – colymore

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

,您可以嘗試。

0

嘗試將android:layout_height設置爲基於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" >