gpt4 book ai didi

android - 自定义 AlertDialog 尺寸太小

转载 作者:行者123 更新时间:2023-11-29 17:57:18 24 4
gpt4 key购买 nike

我正在尝试构建一个简单的自定义警报对话框。只是一个标题,编辑文本和一个按钮。问题是对话框太小而无法正确显示小部件。我尝试实现了不少建议,但没有一个能解决问题。我怎样才能把它扩大到更大的尺寸?我究竟做错了什么?谢谢!

我的代码是:

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();

布局 xml 是:

<?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>

最佳答案

这个答案刚好满足你的要求,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();

关于android - 自定义 AlertDialog 尺寸太小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18473989/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com