Hello all..

Today I will show you two simple ways to remove title in an android alertdialog.

Actually you can do this in two methods.

Method 1

That takes a custom layot file, inflates it, gives it some basic text and icon, then creates it.

AlertDialog.Builder builder;
AlertDialog alertDialog;

Context mContext = getApplicationContext();
LayoutInflater inflater = (LayoutInflater)
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);

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

Method 2

Dialog dialog = new Dialog(context);

But it doesn’t work when creating an AlertDialog (or using the Builder), because it already disables the title and use a custom one internally.

Also, one can do that with a style, eg in styles.xml:

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

And then:

Dialog dialog = new Dialog(context, R.style.FullHeightDialog);


Leave a Reply

Your email address will not be published. Required fields are marked *




Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.