Here is my customdialogclass. It has several constructors in function of what you want to display: buttons, progress, nothing more than a title and a message... Customizing the layout you will be able to have a longer title or not. You could even insert one custom textview that adopts its font size to the space avaible for it. Hope it helps.
public class CustomDialogClass extends Dialog implements android.view.View.OnClickListener {
public Activity c;
public Dialog d;
public Button yes, no;
private int showButtons;
private String tit, msg, yesT, noT;
private boolean custom=false, all= false, progresss=false, spinner=false, indeterminateputted=false, indet=false;
private TextView title, subtit;
private ProgressBar progressBar, progressBar2;
private int max;
private int progress;
public OnPositiveDialogButtonClicked positive;
public CustomDialogClass(Activity a) {
super(a);
this.c = a;
this.custom = false;
}
public CustomDialogClass(Activity a, int botones) {
super(a);
this.c = a;
this.showButtons = botones;
this.custom = false;
}
public CustomDialogClass(Activity a, int botones, String tit, String message) {
super(a);
this.custom = true;
this.c = a;
this.showButtons = botones;
this.tit = tit;
this.msg = message;
}
public CustomDialogClass(Activity a, String tit, String message, String yes, String no) {
super(a);
this.custom = true;
this.c = a;
this.tit = tit;
this.msg = message;
this.yesT = yes;
this.noT = no;
this.all = true;
}
public CustomDialogClass(Activity a, String tit, String message, int max, int progress) {
super(a);
this.progresss = true;
this.tit = tit;
this.msg = message;
this.max = max;
this.progress = progress;
}
public CustomDialogClass(Activity a, String tit, String message, int max, int progress, boolean spinner) {
super(a);
this.tit = tit;
this.msg = message;
this.max = max;
this.progress = progress;
this.spinner = true;
}
public CustomDialogClass(Activity a, String tit, String message, boolean indet) {
super(a);
this.progresss = true;
this.indeterminateputted = true;
this.indet = indet;
this.tit = tit;
this.msg = message;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.dialog_view);
yes = (Button) findViewById(R.id.btn_yes);
no = (Button) findViewById(R.id.btn_no);
title = (TextView) findViewById(R.id.txt_dia);
subtit = (TextView) findViewById(R.id.messageDialog);
progressBar = (ProgressBar) findViewById(R.id.dialogProgress);
progressBar2 = (ProgressBar) findViewById(R.id.dialogProgress2);
if(this.indeterminateputted) this.progressBar.setIndeterminate(indet);
yes.setOnClickListener(this);
no.setOnClickListener(this);
if(tit!=null && tit.length()>0) title.setText(tit);
if(msg!=null && msg.length()>0) subtit.setText(msg);
if(yesT!=null && yesT.length()>0) yes.setText(yesT);
if(noT!=null && noT.length()>0) no.setText(noT);
if(showButtons==0) {
yes.setVisibility(View.GONE);
no.setVisibility(View.GONE);
}
if(spinner) {
subtit.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.GONE);
progressBar2.setVisibility(View.VISIBLE);
yes.setVisibility(View.GONE);
no.setVisibility(View.GONE);
}
if(progresss) {
subtit.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.VISIBLE);
yes.setVisibility(View.GONE);
no.setVisibility(View.GONE);
progressBar.setMax(max);
progressBar.setProgress(0);
}
if(all) {
subtit.setVisibility(View.VISIBLE);
yes.setVisibility(View.VISIBLE);
no.setVisibility(View.VISIBLE);
}
else if(custom){
subtit.setVisibility(View.VISIBLE);
yes.setVisibility(View.GONE);
no.setVisibility(View.GONE);
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_yes:
positive.onPositive(true);
break;
case R.id.btn_no:
positive.onPositive(false);
dismiss();
break;
default:
break;
}
dismiss();
}
public void setButtonListener(OnPositiveDialogButtonClicked listener) {
positive = listener;
}
public void setProgress(int progress) {
if(progressBar!=null) {
this.progress = progress;
progressBar.setProgress(progress);
}
}
public void setMessage(String msg) {
if(subtit!=null) subtit.setText(msg);
}
public void setTitle(String titleee) {
if(title!=null) title.setText(titleee);
}
public int getProgress() {
return this.progress;
}
public int getMax() {
return this.max;
}
public void setIndeterminate(boolean indet) {
this.progresss = true;
this.indeterminateputted = true;
this.indet = indet;
}
}
the interface for the buttons:
public interface OnPositiveDialogButtonClicked {
public void onPositive(boolean clickedYes);
}
the layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@color/white" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/gradientbackground"
android:orientation="horizontal" >
<TextView
android:id="@+id/txt_dia"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:layout_marginLeft="10dp"
android:textColor="@android:color/white"
android:textSize="16sp"
android:textStyle="bold"
>
</TextView>
</LinearLayout>
<TextView
android:id="@+id/messageDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"
android:layout_margin="10dp"
android:textColor="@color/black"
android:textSize="13sp"
android:visibility="gone"
android:textStyle="bold" >
</TextView>
<ProgressBar
style="@android:style/Widget.ProgressBar.Horizontal"
android:id="@+id/dialogProgress"
android:layout_margin="10dp"
android:visibility="gone"
android:layout_gravity="center"
android:layout_width="250dp"
android:layout_height="4dp"
/>
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:id="@+id/dialogProgress2"
android:visibility="gone"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="45dp"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="5dp"
android:background="@color/white"
android:orientation="horizontal" >
<Button
android:id="@+id/btn_yes"
android:layout_width="100dp"
android:layout_height="45dp"
android:background="@android:color/white"
android:clickable="true"
android:text="Yes"
android:textSize="13sp"
android:textColor="#5DBCD2"
android:textStyle="bold" />
<Button
android:id="@+id/btn_no"
android:layout_width="100dp"
android:layout_height="45dp"
android:layout_marginLeft="5dp"
android:background="@android:color/white"
android:clickable="true"
android:text="No"
android:textSize="13sp"
android:textColor="#5DBCD2"
android:textStyle="bold" />
</LinearLayout>