-1

I want to remove title section from dialog box in Android and I want to use my own created xml file as Dialog box.

ADM
  • 20,406
  • 11
  • 52
  • 83
  • 2
    what's stopping you then? – BlackBeard Nov 29 '17 at 05:41
  • Share your code for dialog box – AGM Tazim Nov 29 '17 at 05:41
  • 1
    Possible duplicate of [https://stackoverflow.com/questions/6263639/android-dialog-removing-title-bar](https://stackoverflow.com/questions/6263639/android-dialog-removing-title-bar) – yashkal Nov 29 '17 at 05:46
  • Possible duplicate of [How to create a Custom Dialog box in android?](https://stackoverflow.com/questions/13341560/how-to-create-a-custom-dialog-box-in-android) – ADM Nov 29 '17 at 05:47

4 Answers4

0

Here is code for same:

    final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getContext());
            LayoutInflater layoutInflater = getActivity().getLayoutInflater();
            final ViewGroup viewGroup = null;
            View dialogView = layoutInflater.inflate(R.layout.custom_email_dialog, viewGroup, false);

            dialogBuilder.setView(dialogView);
            final AlertDialog alertDialog = dialogBuilder.create();
            alertDialog.show();

Here is "custom_email_dialog" is custom XML that we need to show on dialog.

and you can access dialog element as:

  TextView headerTextView = (TextView) dialogView.findViewById(R.id.emailHeader);
halfer
  • 19,824
  • 17
  • 99
  • 186
Ankit Patidar
  • 2,731
  • 1
  • 14
  • 22
0

Inflate your XML. Like this

            AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context);
            LayoutInflater inflater = context.getLayoutInflater();
            final View dialogView = inflater.inflate(R.layout.yourlayout, null);
            dialogBuilder.setView(dialogView);

            AlertDialog b = dialogBuilder.create();
            b.show();
0

You can inflate your own layout and set it to you Dialog.

Dialog dialog = new Dialog(ProfileSettingsActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.uploadphoto); // Your layout here
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.WRAP_CONTENT; //Custom width and height
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
dialog.getWindow().setAttributes(lp);
dialog.setCancelable(true);
dialog.show();
Yamini Balakrishnan
  • 2,361
  • 16
  • 24
0

Simply add style to dialog and remove title of the custom dialog.

Custom_dialog.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    android:orientation="vertical">

    <TextView
        android:id="@+id/txt_warning"`enter code here`
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="10dp"
        android:text="Warning"
        android:textAllCaps="true"
        android:textColor="@android:color/white"
        android:textSize="18dp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/txt_dia"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="10dp"
        android:text="Are you sure you want to Logout?"
        android:textColor="@android:color/white"
        android:textSize="18dp" />

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_marginTop="15dp"
        android:background="@android:color/white" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:orientation="horizontal"
        android:weightSum="1">

        <Button
            android:id="@+id/btn_no"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:layout_weight=".5"
            android:background="@color/colorPrimary"
            android:clickable="true"
            android:gravity="center"
            android:padding="10dp"
            android:text="No"
            android:textColor="@android:color/white"
            android:textSize="18dp" />

        <View
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="@android:color/white" />

        <Button
            android:id="@+id/btn_yes"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight=".5"
            android:background="@color/colorPrimary"
            android:clickable="true"
            android:gravity="center"
            android:padding="10dp"
            android:text="Yes"
            android:textColor="@android:color/white"
            android:textSize="18dp" />

    </LinearLayout>

</LinearLayout>

Set style in Styles.xml:-

<style name="FullHeightDialog" parent="android:style/Theme.Dialog">
        <item name="android:windowNoTitle">true</item>
    </style>

On button Click listener you have to write this code:-

// custom dialog

 final Dialog dialog = new Dialog(mContext, R.style.FullHeightDialog);
 dialog.setContentView(R.layout.custom_dialog);
 dialog.setCancelable(false);

WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
dialog.getWindow().setAttributes(lp);

dialog.show();

Button btnYes = (Button) dialog.findViewById(R.id.btn_yes);
Button btnNo = (Button) dialog.findViewById(R.id.btn_no);
 // if button is clicked, close the custom dialog
 btnYes.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            documentImage = documentImagesList.get(getAdapterPosition());

                          //logout code here
                        }
});
btnNo.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            dialog.dismiss();
                        }
});