Android: How to Create a Dialog Without a Title

Android: How to create a Dialog without a title?

You can hide the title of a dialog using:

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);


Previous version of this answer, which is overcomplicated:

You need to use an AlertDialog. There's a good explanation on the Android Developer's site about custom dialogs.

In very short summary, you do this with code like copied below from the official website. That takes a custom layot file, inflates it, gives it some basic text and icon, then creates it. You'd show it then with alertDialog.show().

AlertDialog.Builder builder;
AlertDialog alertDialog;

Context mContext = getApplicationContext();
LayoutInflater inflater = (LayoutInflater)
mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_dialog,
(ViewGroup) findViewById(R.id.layout_root));

TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("Hello, this is a custom dialog!");
ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageResource(R.drawable.android);

builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
alertDialog = builder.create();

In response to comment:

I assume that TextView with the id nr is in the View you are inflating with View view = inflater..... If so, then you need to change just one bit: instead of dialog.findView... make it view.findView.... Then once you've done that, remember to use dialog.show(), or even builder.show() without bothering to do builder.create().

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.

How to remove Alert dialog Title bar

If you don't want title bar in alert dialog then just remove below line from code.

dialogbuilder.setTitle("Login");

If still not working then add below line.

dialogbuilder.requestWindowFeature(Window.FEATURE_NO_TITLE);

How to create a DialogFragment without title?

Just add this line of code in your HelpDialog.onCreateView(...)

getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);

This way you're explicitly asking to get a window without title :)



EDIT

As @DataGraham and @Blundell pointed out on the comments below, it's safer to add the request for a title-less window in the onCreateDialog() method instead of onCreateView(). This way you can prevent ennoying NPE when you're not using your fragment as a Dialog:

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);

// request a window without the title
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
return dialog;
}

Android Dialog: Removing title bar

use,

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

Dialog box without title

try this while creating dialog

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

Android activity as dialog, but without a title bar

Try doing requestWindowFeature(Window.FEATURE_NO_TITLE); in onCreate. It'll need to be done immediately after calling super.onCreate and just before setContentView.

How to remove the title in Dialog?

if Dialog ..............

Dailog dialog = new Dialog(MainActivity.this, R.style.mydialogstyle);

res-->values-->mydialog.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="mydialogstyle" parent="android:style/Theme.Dialog">
<item name="android:windowBackground">@null</item>
<item name="android:windowNoTitle">false</item>
</style>
</resources>

Remove title from dialog in Android

Why do you set a title for your dialog and you already want to remove the title? You should do something like this:

final Dialog dialog = new Dialog(this);
LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.splash, null)
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.setContentView(view);
dialog.show();


Related Topics



Leave a reply



Submit