5

I have this DialogFragment. When I show it, it becomes fullscreen, I mean it overlaps the current screen. How to make it small like an AlertDialog?

I guessed it's because of the RelativeLayout so I wrapped the LinearLayout outside of RelativeLayout but nothing changes.

public class LoginDialogFragment extends DialogFragment {

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme);
}

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    final View v = inflater.inflate(R.layout.login_dialog, container, false);
    final EditText emailEditText = (EditText)v.findViewById(R.id.emailEditText);
    final EditText passwordEditText = (EditText)v.findViewById(R.id.passwordEditText);
    final Button loginButton = (Button)v.findViewById(R.id.loginButton);
    loginButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(final View v) {
                checkLogin(emailEditText.getText().toString(), passwordEditText.getText().toString());
            }
        });
    return v;
}
}

Layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

    <TextView
        android:id="@+id/loginTitleTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:text="@string/loginDialogTitle"
        android:textColor="@color/White"
        android:textSize="20sp" />

    <EditText
        android:id="@+id/emailEditText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/loginTitleTextView"
        android:layout_weight="1"
        android:ems="10"
        android:inputType="textEmailAddress" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/passwordEditText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/emailEditText"
        android:layout_weight="1"
        android:ems="10"
        android:inputType="textPassword" />

    <TextView
        android:id="@+id/passwordTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/passwordEditText"
        android:layout_alignBottom="@+id/passwordEditText"
        android:layout_alignParentLeft="true"
        android:layout_weight="1"
        android:text="@string/password"
        android:textColor="@color/White"
        android:textSize="16sp" />

    <TextView
        android:id="@+id/emailTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/emailEditText"
        android:layout_alignBottom="@+id/emailEditText"
        android:layout_alignParentLeft="true"
        android:layout_weight="1"
        android:text="@string/email"
        android:textColor="@color/White"
        android:textSize="16sp" />

    <Button
        android:id="@+id/loginButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/passwordEditText"
        android:text="@string/loginButtonText" />

    </RelativeLayout>

</LinearLayout>
2
  • Have you figured this out by any chance? Aug 19, 2012 at 1:13
  • @Emerald214 try this yourFragmentAct act = new yourfragmentActivity();act.show(); instead of add as fragment .It will show and resize based on the content
    – Sugan S
    Jul 22, 2013 at 12:17

1 Answer 1

2

Call setStyle(STYLE_NORMAL, android.R.style.Theme_Dialog); instead of setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme); in onCreate(). Did it help?

2
  • What's your base theme? Try setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Holo_Light_Dialog); inside the onCreate() method May 30, 2013 at 23:46
  • I have the same problem and this doesn't change anything at all Jan 24, 2015 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.