JFFF
JFFF

Reputation: 989

Wrap android dialog title on multiple lines

Is there a way to wrap a title in a Android custom dialog box to multiple line ? Without having to make an AlertDialog ?

dialog.setContentView(R.layout.custom_dialog);
dialog.setTitle(itemTitle);

"itemTitle" is sometimes way too long and only half of the text is displayed.enter image description here

Upvotes: 1

Views: 5735

Answers (4)

jsidera
jsidera

Reputation: 1841

You can use inflate the title with a completely customized view, I think this is the easiest way. Something like this:

AlertDialog.Builder builder = new AlertDialog.Builder(this);

String infService = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(infService);

View titleView = inflater.inflate(R.layout.dialog_title, null);

builder.setCustomTitle(titleView);

Where R.layout.dialog_title can be a TextView with multiple lines, or anything you want.

Upvotes: 1

Amjad Abu Saa
Amjad Abu Saa

Reputation: 1664

Answer copied from this question

You can make dialog title multiline:

TextView title = (TextView) dialog.findViewById(android.R.id.title);
title.setSingleLine(false);

Upvotes: 7

iliask
iliask

Reputation: 535

You can put a TextView at the beginning of whatever parent layout you are using for your dialog:

<TextView
    android:id="@+id/mydialogtitle"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="@color/white"
    android:background="@color/black"
    android:textSize="20sp" />

and add:

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.mydialog);
TextView dialogTitle = (TextView) dialog.findViewById(R.id.mydialogtitle);
dialogTitle.setText("My dialog title");

Upvotes: 1

Related Questions