Reputation: 989
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.
Upvotes: 1
Views: 5735
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
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
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
Reputation: 530
Use popupwindow http://virenandroid.blogspot.com/2011/11/custom-popupwindow-android.html
Upvotes: 0