How to remove title from AlertDialog in android?
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)
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();
alertDialog.show()
Method 2
Dialog dialog = new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
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> </style>
And then:
Dialog dialog = new Dialog(context, R.style.FullHeightDialog);
Link to this post!