Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is android custom dialog coming fullscreen

I am trying to create custom dialog

Base Layout(I have also tried various modified layouts)

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:background="@color/dialogHeaderBackground"
            android:gravity="center"
            android:minHeight="@dimen/minHeightDialogTitle"
            android:text=""
            android:textStyle="bold" />

        <TextView
            android:id="@+id/message"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/title"
            android:layout_marginTop="5dp"
            android:text="" />

        <LinearLayout
            android:id="@+id/loutButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_below="@+id/message"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="5dp"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/btnNeutral"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="" />

            <Button
                android:id="@+id/btnNegative"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="" />

            <Button
                android:id="@+id/btnPositive"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="" />
        </LinearLayout>
    </RelativeLayout>

Java Code

        Dialog dialog = new Dialog(this);
//      Dialog dialog = new Dialog(this,R.style.Theme_Dialog);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

        dialog.setContentView(R.layout.custom_dialog);

        Button btnPositive=(Button) dialog.findViewById(R.id.btnPositive);
        Button btnNegative=(Button) dialog.findViewById(R.id.btnNegative);
        Button btnNeutral=(Button) dialog.findViewById(R.id.btnNeutral);

        TextView txvTitle=(TextView)dialog.findViewById(R.id.title);
        TextView txvMessage=(TextView)dialog.findViewById(R.id.message);
        ...
        so on and so forth

I get following dialog, which is fullscreen, WHICH I DO NOT WANT

fullscreen dialog

Solutions Already Tried, which give same results as above screenshot

  1. Styles.xml configuration 1 | Implemented Pastebin code
  2. Styles.xml configuration 2 | Implemented Pastebin code
  3. The example provided in Android Dev Guide using AlertDialog.Builder | Implemented Java Code
  4. None of my underlying layout use MATCH_PARENT in height. As said in this Stack overflow answer
  5. Also try to change window settings to WRAP_CONTENT for dialog based on answer here | Implemented Java Code in Pastebin
  6. Have also tried to keep entire RelativeLayout inside a parent LinearLayout, see the 3rd comment in following answer

The only time I can get decent dialog is when specifying height for the xml layout, like this android:layout_height="150dp"

 <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"        
        android:layout_width="match_parent"
        android:layout_height="150dp" >

Dialog when fixed height is specified,

  1. The content/layout goes missing when message is bigger more text in dialog message
  2. When message is smaller, dialog is displayed bigger than required, see below OK button less text is dialog message

Don't suggest the above(specify fixed height) as solution as it is not efficient and not looking that good and also not dynamic, its static

Question

What to do specify,decent looking custom dialog which is customizable too?

I am willing to give bounty as a token of appreciation if you can help me solve this issue

EDIT: Provided bounty to correct solution.

like image 936
Akhil Jain Avatar asked Aug 28 '15 06:08

Akhil Jain


1 Answers

remove android:layout_alignParentBottom="true"line from linear layout

like image 100
Prachi Avatar answered Sep 21 '22 21:09

Prachi