Custom Dialog without title and border

Based on the code here,
http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog . I am successfully able to create a custom dialog with background and buttons inside, but there’s still something not right. there still a space for title bar, and there are border around the view. how to get rid of these title and border?

here is my dialog

  • Android onConfigurationChanged: how to save and restore fragment back stack?
  • Storage limit in raw and asset folder in android
  • Kotlin Android Extensions and Fragments
  • Create a Bitmap/Drawable from file path
  • Android Studio - Gradle sync project failed
  • Play Google (Android store) Statistics
  • Dialog pauseMenu = new Dialog(this,R.xml.pause_dialog);
    pauseMenu.setContentView(R.layout.pause_menu);
    return pauseMenu;
    

    and here is my pause layout

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:id="@+id/linearLayout1" android:layout_width="wrap_content" android:background="@drawable/pause_menu_cropped" android:layout_gravity="center" android:gravity="center|center_horizontal">
        <TableLayout android:layout_width="wrap_content" android:id="@+id/tableLayout1" android:layout_height="wrap_content">
            <ImageButton android:src="@drawable/pause_button_quit" android:layout_width="wrap_content" android:background="@drawable/pause_button_quit" android:id="@+id/imageButton2" android:layout_height="wrap_content"></ImageButton>
            <ImageButton android:src="@drawable/pause_button_option" android:layout_width="wrap_content" android:background="@drawable/pause_button_option" android:id="@+id/imageButton1" android:layout_height="wrap_content"></ImageButton>
        </TableLayout>
    </LinearLayout>
    

    Related posts:

    Android WebView with an embedded youtube video, full screen button freezes video
    WebView Crash by java.io.IOException: close failed: EIO (I/O error) libcore.io.IoUtils.close(IoUtils...
    New Relic Class Not Found &hellip; I don&#039;t even use new relic
    Bluetooth LE ScanFilters don&#039;t work on Android M
    The best way to caching json
    Android: Adding a fragment to an activity
  • Android Gallery with pinch zoom
  • How to make soap post request using Volley library in Android
  • Android Dialog theme makes icon too light
  • Android add border to edit text programmatically
  • AppCompatSpinner's entries not opening TimePickerDialog on selecting it second time. Please see details
  • How to reset Google Advertising ID in Android Programatically?
  • 9 Solutions collect form web for “Custom Dialog without title and border”

    A Dialog cannot be created without a title. Further down in that tutorial it mentions:

    A dialog made with the base Dialog
    class must have a title. If you don’t
    call setTitle(), then the space used
    for the title remains empty, but still
    visible. If you don’t want a title at
    all, then you should create your
    custom dialog using the AlertDialog
    class. However, because an AlertDialog
    is created easiest with the
    AlertDialog.Builder class, you do not
    have access to the setContentView(int)
    method used above. Instead, you must
    use setView(View). This method accepts
    a View object, so you need to inflate
    the layout’s root View object from
    XML.

    This answer solves both the title and the border problem using a custom style.

    I think this will help you out

    gameOver would be the dialog name and in setContentView it would be ur custom dialog layout

    gameOver = new Dialog(Main.this);
    gameOver.requestWindowFeature(Window.FEATURE_NO_TITLE);
    gameOver.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    gameOver.setCancelable(false);
    gameOver.setContentView(R.layout.gameover);
    
    1. Make a class like this:

      public class CustomDialog extends Dialog {
          public AlertFinishiView(Context context) {
              super(context);
              requestWindowFeature(Window.FEATURE_NO_TITLE);
              setContentView(R.layout.dialog);
              getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
          }
      }
      
    2. make a xml in layut folder with this name dialog

      <?xml version="1.0" encoding="utf-8"?>
      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent" 
         android:background="@android:color/transparent">
      
         <RelativeLayout 
            android:layout_width="220dp" 
            android:layout_height="140dp" 
            android:layout_centerHorizontal="true" 
            android:layout_centerVertical="true"            
            android:background="@drawable/bg_custom_dialog" >
      
            <Button android:id="@+id/button1" 
               android:layout_width="wrap_content" 
               android:layout_height="wrap_content" 
               android:layout_centerHorizontal="true" 
               android:layout_centerVertical="true" 
               android:text="Button" />
      
         </RelativeLayout>
      
      </RelativeLayout>
      
    3. add the image above in your drawable folder with name bg_custom_dialog.9.png

    bg_custom_dialog

    1. call in your activity:

      CustomDialog customDialog = new CustomDialog(this);
      customDialog.show();
      
    Dialog dialog = new Dialog(Main.this);
    dialog.getWindow();
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    
    Dialog dialog = new Dialog(context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    

    Try the following style in your styles.xml:

    <style name="free_floating_dialog" parent="@android:style/Theme.Holo.Light.Dialog">
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowCloseOnTouchOutside">false</item>
    </style>
    

    For more options see “Theme.Holo.Light.Dialog” which is part of the Android sources (since Honeycomb), or any other dialog style you based your’s on.

    Then simply use this style as basis to your own dialog:

    Dialog myDialog = new Dialog(getActivity(), R.style.free_floating_dialog);
    myDialog.setContentView(R.layout.myContent);
    

    Use this, It works perfectly;

                 dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); //before     
                 dialog.setContentView(R.layout.your_dialog_layout);
    

    How to create a completely custom Dialogue/Popup in Android (change overlay colour and dialogue window layout)

    this would give you as possible ways as that would help to improve this problem

    I use this code and it work fine:

    AlertDialog.Builder builder = new AlertDialog.Builder(contextActivity,android.R.style.Theme_Holo_Dialog_NoActionBar);
    AlertDialog alertDialog = builder.create();
    alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    alertDialog.setView(myLayout,0,0,0,0);
    alertDialog.show();
    
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.