kayton
kayton

Reputation: 3759

Custom Layout for Dialog across different versions?

I have a Dialog with a custom layout (very simple). I set it up using the code below:

public static Dialog createGPSDialog(final Activity activity, boolean isLocationEnabled) {
    final Dialog dialog = new Dialog(activity, R.style.Theme_Sherlock_Light_Dialog);

    LinearLayout contentView = (LinearLayout) activity.getLayoutInflater().inflate(R.layout.dialog_twobutton, null);

    dialog.setContentView(contentView);
    return dialog;
}

There's some code I omitted, but it isn't relevant. Anyway, this is how it looks in gingerbread:

gingerbread

and this is how it looks on jellybean (probably ics as well):

jellybean

The title area for the dialog is kept on JB, even after setting ContentView. Is there a workaround for this?

Upvotes: 0

Views: 103

Answers (2)

A--C
A--C

Reputation: 36449

If you want to be completely custom and get rid of the title bar, try adding this line to your code:

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

Upvotes: 1

Nathan
Nathan

Reputation: 1767

The key is defining a theme for your dialog. The constructor for Dialog takes a theme resources id. Just use one of android's android.R.theme.xxx.

When using the AlertDialog.Builder you can define a new theme using the contextthemewrapper. http://developer.android.com/reference/android/view/ContextThemeWrapper.html

Upvotes: 0

Related Questions