AndroidDev
AndroidDev

Reputation: 21237

Custom AlertDialog size is too small

I'm trying to build a simple custom alert dialog. Just a header, and edit text, and a button. Problem is that the dialog is too small to properly display the widgets. I've tried to implement quite a few suggestions, but none of them solve the issue. How can I expand this to a larger size? What am I doing wrong? Thanks!

My code is:

LayoutInflater inflater = LayoutInflater.from(this);
View builderView = inflater.inflate(R.layout.enter_password, null);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(builderView);   
AlertDialog alert = builder.create();   
alert.show();

The layout xml is:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    android:background="@drawable/background_gray_gradient" >

    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20dp"
        android:orientation="horizontal" >

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="70dp"
            android:layout_gravity="left"

            android:contentDescription="@string/blank"
            android:src="@raw/lock" >
        </ImageView>    

        <TextView
            android:layout_marginTop="15dp"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textColor="#000000"
            android:paddingTop="5dip"
            android:paddingLeft="5dp"
            android:text="@string/password_to_continue_title"
            android:textSize="20sp" />

    </LinearLayout>

    <EditText
        android:id="@+id/password"
        android:inputType="textPassword"
        android:hint="@string/password"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <Button
            android:id="@+id/submit_password"
            style="@style/ButtonText"
            android:onClick="submitPassword"
            android:layout_gravity="center_horizontal"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:background="@drawable/gray_button"
            android:text="@string/continue_on" />

</LinearLayout>

Upvotes: 1

Views: 6338

Answers (1)

Rachit Mishra
Rachit Mishra

Reputation: 6112

This answer just satisfies your requirements, https://stackoverflow.com/a/10912076/826657

       Rect displayRectangle = new Rect();
        Window window = this.getWindow();
        window.getDecorView().getWindowVisibleDisplayFrame(displayRectangle);
        LayoutInflater inflater = LayoutInflater.from(this);
        View builderView = inflater.inflate(R.layout.activity_dia, null);
        builderView.setMinimumWidth((int) (displayRectangle.width() * 0.9f));
        builderView.setMinimumHeight((int) (displayRectangle.height() * 0.9f));
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setView(builderView);
        AlertDialog alert = builder.create();
        alert.show();

Upvotes: 3

Related Questions