Search code examples
androidcustomdialog

Custom AlertDialog Borders


I am creating a custom dialog. Its example code is:

final AlertDialog dialog;

protected AlertDialog createDialog(int dialogId) {
    AlertDialog.Builder builder;
    builder = new AlertDialog.Builder(parent);
    AlertDialog fDialog = null;

    switch(dialogId) {
        case Constants.cusDialogtId:
            builder = new AlertDialog.Builder(parent);
            builder.setTitle("Title");
            LayoutInflater inflater = (LayoutInflater)parent.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View view = inflater.inflate(R.layout.customdialog, null);
            builder.setView(view);
            fDialog = builder.create();
            break;
    }
    dialog = fDialog;
    return dialog;
}

The problem is that when the dialog is shown, it has a gray background of the native dialog whose some top and bottom border is also shown with my custom dialog. Is there some way to show only my custom dialog view...???

The XML I am using is:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical"
android:background="@drawable/bgsmall" >
<EditText android:id="@+id/redeemamount"
android:layout_width="fill_parent"
android:layout_height="wrap_content" 
android:layout_marginTop="10dip"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:hint="Enter amount"
android:inputType="numberDecimal">
</EditText>             
<Button android:id="@+id/submitRedeemAmountButton"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:text="Submit"
android:textColor="#FFFFFF"
android:textStyle="bold"
android:background="@drawable/buttoncorner"
android:layout_marginTop="20dip"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:layout_marginBottom="20dip">
</Button>
</LinearLayout>

Solution

  • I don't think you can remove the borders by using AlertDialog.Builder.

    What you can do is create a CustomDialog class that extends Dialog and in the constructor of your CustomDialog you inflate your customdialog.xml.

    Also you will need to create a custom style for your dialog, that hides the borders. Here is an example:

        <style
          name="CustomStyle"
          parent="android:Theme.Dialog">
          <item
              name="android:windowBackground">@color/transparent</item>
          <item
              name="android:windowContentOverlay">@null</item>
        </style>
    

    Also define the transparent color:

       <color
          name="transparent">#00000000</color>
    

    And you will create your dialog using :

        CustomDialog dialog=new CustomDialog(this,R.style.CustomStyle);