Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7926135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:37:43+00:00 2026-06-03T18:37:43+00:00

This question has been asked before: AlertDialog custom title has black border But was

  • 0

This question has been asked before: AlertDialog custom title has black border

But was not answered satisfactorily – and is missing some information.


I’m trying to create a custom dialog in Android without a title and without any buttons along the bottom.

However, the resulting dialog has black “borders”/”spacing”/something along the top and bottom of the view.

From the Documentation:

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.

So, that’s what I did:

Welcome.java

public class Welcome  extends Activity
{
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.welcome);

        LayoutInflater inflater = (LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.welcomedialog, (ViewGroup)findViewById(R.id.layout_root));

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setView(layout);
        builder.create().show();
    }
}

welcomedialog.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:background="@drawable/texturebg"
              android:id="@+id/layout_root"
              android:orientation="vertical"
              android:padding="40px">
    ...
</LinearLayout>

NOTE: I’ve tried using FrameLayout as the root ViewGroup instead of LinearLayout as per a suggestion I found somewhere – but that didn’t help.

Result

enter image description here
enter image description here


setBackgroundDrawable Suggestion

public class Welcome  extends Activity
{
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.welcome);

        LayoutInflater inflater = (LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.welcomedialog, (ViewGroup)findViewById(R.id.layout_root));

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setView(layout);
        AlertDialog dialog = builder.create();

        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));

        dialog.show();
    }
}

Didn’t work for me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T18:37:44+00:00Added an answer on June 3, 2026 at 6:37 pm

    If you look at the AlertDialog class source you’ll see most of the methods are simply proxy methods (facade) around private AlertController mAlert.

    Looking at the AlertController class source you’ll see 4 interesting member variables:

    private int mViewSpacingLeft;
    private int mViewSpacingTop;
    private int mViewSpacingRight;
    private int mViewSpacingBottom;
    private boolean mViewSpacingSpecified = false;
    

    Setting mViewSpacingSpecified to true will remove the borders on the top and bottom of the dialog.

    This is done properly by changing this line:

    dialog.setView(layout);
    

    to:

    dialog.setView(layout, 0, 0, 0, 0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So this question has been asked before , but not answered in great detail.
This question has been asked before, but not answered. Is there a list anywhere
Now this question has been asked before but I am not able to get
I know this question has been asked before but the solutions did not work
I suspect this question has been asked before, but it's not easy to Google
This question has been asked before, but the answered ones I could find were
I'm sorry if this question has been asked before, but I'm not even sure
This question has been asked before but never really answered (at least the way
This question has been asked before but with no answer. I'm running into brick
This question has been asked before ( link ) but I have slightly different

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.