Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom dialog opens full screen

Tags:

android

I'm developing an Android application and I have a question about custom dialogs.

I do this to open a custom dialog:

protected void showSetFriendEmailDialog()
{
    // Create the dialog.
    final Dialog emailDialog = 
            new Dialog(FriendHomeActivity.this, android.R.style.Theme_DeviceDefault);
    emailDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

    emailDialog.setCancelable(true);
    emailDialog.setContentView(R.layout.dialog_add_friend_email);

    // Get dialog widgets references.
    final EditText editFriendsEmail = (EditText)emailDialog.findViewById(R.id.editEmailAddFriendEmail);
    Button btnAccept = (Button)emailDialog.findViewById(R.id.btnAddFriendEmail);

    // Set on click lister for accept button
    btnAccept.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View view)
        {
            // Get selected values
            String friendEmail = 
                    editFriendsEmail.getText().toString();

            // Close dialog.
            emailDialog.dismiss();

            // TODO: Call api to send email to web service using friendsEmail var.
            Log.v(TAG, "Friend email: " + friendEmail);
        }
    });

    //now that the dialog is set up, it's time to show it    
    emailDialog.show();
}

And this is its layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textAddFriendEmail"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/layout_set_friend_email"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/editEmailAddFriendEmail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textEmailAddress" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/btnAddFriendEmail"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/ok" />

</LinearLayout>

But it opens full screen.

What do I have to do to open it as an AlertDialog?

like image 943
VansFannel Avatar asked Jul 05 '13 08:07

VansFannel


2 Answers

you have to use android.R.style.Theme.Dialog instenad of android.R.style.Theme_DeviceDefault

like image 114
Blackbelt Avatar answered Oct 17 '22 18:10

Blackbelt


Use R.style.Theme_AppCompat_Dialog in order to get the proper dialog.

like image 32
Tejas lataye Avatar answered Oct 17 '22 18:10

Tejas lataye