我的自定义对话框有顶部和底部填充。如何删除?

时间:2014-04-29 16:58:56

标签: android alertdialog customdialog

我创建了一个自定义对话框但是我得到了意想不到的结果。

对话框的最终外观是:

enter image description here

正如您所看到的,我的自定义对话框在对话框的顶部和底部都显示了一种填充,我不编写它来执行此操作...

代码是下一个:

@Override

protected Dialog onCreateDialog(int id){
LayoutInflater  inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View newAsig = inflater.inflate(R.layout.nuevaasignatura_act, null);

//Also, down here I tried to shape the dialog by setting a functional resource, but
    //the stroke should be blue, not grey.

    RelativeLayout re = (RelativeLayout)newAsig.findViewById(R.id.layoutCrearAsig1);
    re.setBackgroundResource(R.drawable.borde);

    Typeface tf = Typeface.createFromAsset(getAssets(), "Roboto-Light.ttf");

    ImageView ico = (ImageView)newAsig.findViewById(R.id.ivicono);
    ico.setBackgroundResource(R.drawable.colorprincipal);

    LinearLayout ly = (LinearLayout)newAsig.findViewById(R.id.layoutCrearAsig2);
    ly.setBackgroundColor(Color.rgb(214, 217, 224));

    TextView txt = (TextView)newAsig.findViewById(R.id.textviewnuevaasig);
    txt.setTypeface(tf);

    TextView txt1 = (TextView)newAsig.findViewById(R.id.textViewCarpeta);
    txt1.setTypeface(tf);
    txt1.setBackgroundResource(R.drawable.colorprincipal);

    Button btn = (Button)newAsig.findViewById(R.id.buttonCrearAsig);
    btn.setTypeface(tf);

    switch (id){
    case 0:
        return new AlertDialog.Builder(this)
        .setView(newAsig).create();
    }return null;

XML文件......

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/layoutCrearAsig1">

<ImageView
    android:id="@+id/ivicono"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:paddingLeft="4dp"
    android:background="@color/DarkGray"
    android:contentDescription="Icono ClassMarks"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:src="@drawable/icono_cm" />

 <TextView
     android:id="@+id/textViewCarpeta"
     android:layout_width="match_parent"
     android:layout_height="50dp"
     android:layout_toRightOf="@id/ivicono"
     android:background="@color/DarkGray"
     android:clickable="true"
     android:gravity="center"
     android:text="Carpeta"
     android:textAppearance="?android:attr/textAppearanceLarge" />

     <LinearLayout 
         android:id="@+id/layoutCrearAsig2"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_below="@id/ivicono"
         android:orientation="vertical">

         <TextView
             android:id="@+id/textviewnuevaasig"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_gravity="center_horizontal"
             android:layout_marginTop="20dp"
             android:text="Crear nueva asignatura"
             android:textSize="20sp" />

         <EditText
             android:id="@+id/edittextAsig"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:ems="10"
             android:layout_gravity="center_horizontal"
             android:layout_marginTop="20dp" >
         </EditText>

         <Button 
             android:id="@+id/buttonCrearAsig"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_gravity="center_horizontal"
             android:layout_marginTop="20dp"
             android:layout_marginBottom="20dp"
             android:paddingLeft="10dp"
             android:paddingRight="10dp"
             android:textSize="20sp"
             android:text="Crear"/>

     </LinearLayout>

</RelativeLayout>

我希望你能帮助我。谢谢!

2 个答案:

答案 0 :(得分:4)

这个想法是AlertDialog始终有5dp上下填充。

尝试这样的事情:

AlertDialog dialog = new AlertDialog.Builder(this).create();
dialog.setView(newAsig, 0, 0, 0, 0);

答案 1 :(得分:0)

尝试此验证。

public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        builder = new AlertDialog.Builder(getActivity());
        builder.setInverseBackgroundForced(true);
    } else {
        builder = new AlertDialog.Builder(getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
    }
}