0

I'm trying to create a custom dialog box but it's both making it as wide as the screen (minus padding) but more importantly it's adding about an inch to the top in white (the background colour is red) above the first textview. What I want is a dialog box just as big as it needs to fill the content.

If I change any layout from fill_parent to wrap_content I get the contents about the size of the image and everything else (i.e. the text) is truncated.

What am I doing wrong?

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/customdialog"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/titledialog"
android:orientation="vertical" >

<TextView
    android:id="@+id/textTitle"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@color/titleback"
    android:gravity="center"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textColor="@color/title" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="15dp" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:paddingBottom="24dp"
        android:paddingTop="48dp"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/textContent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center"
        android:text="TextView" />

</LinearLayout>

<Button
    android:id="@+id/buttonCustomDialogOk"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="Close" />

Neil Walker
  • 6,400
  • 14
  • 57
  • 86
  • The white section doesn't stand for title? – gunar Sep 20 '13 at 06:03
  • possibly, that's what I thought, but how to get rid of it? also this is only on JB, if I run same on gingerbread the dialog is the width of an image and almost all text is lost – Neil Walker Sep 20 '13 at 14:24
  • Check [this link](http://stackoverflow.com/a/6263721/1051783) on how to remove the title. – gunar Sep 20 '13 at 14:28

2 Answers2

0

I found the answer here Android: How to create a Dialog without a title?

Apparently the top blank bit is the title of the layout and you cannot get rid of it unless you use an AlertDialog and not a Dialog.

ah, thanks for the update. Android Dialog: Removing title bar

you can do it like this

Community
  • 1
  • 1
Neil Walker
  • 6,400
  • 14
  • 57
  • 86
0

Dialog dialog = new Dialog(context, R.style.FullHeightDialog); (OR Try This) getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);

Narendra
  • 1,010
  • 1
  • 12
  • 11