android– 如何调整AlertDialog.Builder的大小?

android– 如何调整AlertDialog.Builder的大小?,第1张

概述我想调整我的AlertDialog.Builder的大小,但我没有在这个网站上找到任何解决方案,我尝试了我在thisone这样的问题上看到的所有东西,但看起来比我想要的还要老,我正在看的代码没有现在就工作……ALERTDIALOGBUILDER.JAVApublicclassAlertDialogInfoextendsAlertDialog.Builde

我想调整我的AlertDialog.Builder的大小,但我没有在这个网站上找到任何解决方案,我尝试了我在this one这样的问题上看到的所有东西,但看起来比我想要的还要老,我正在看的代码没有现在就工作……

ALERTDIALOGBUILDER.JAVA

public class AlertDialogInfo extends AlertDialog.Builder {public AlertDialogInfo(Context context, String Title, String msg) {    super(context);    AlertDialog.Builder builder = new AlertDialog.Builder(context,R.style.AppCompatAlertDialogStyle);    builder.setTitle(Title);    builder.setMessage(msg);    builder.setNegativebutton("OK",new DialogInterface.OnClickListener() {        @OverrIDe        public voID onClick(DialogInterface dialog, int which) {            dialog.dismiss();        }    });    }}

我试图将AlertDialog.Builder变为AlertDialog以调整其大小,但只显示一个没有数据的黑色方块.

问题:如何使用大文本制作AlertDialog.Builder? (需要滚动肯定,因为我不想让对话框像我的屏幕一样大)

更新:

我想要的是这样的东西,我必须通过Bundle更改文本,我从我的AppCompatActivity调用AlertDialog使用FrameLayout(我不知道应该用什么样的Dialog来覆盖我需要的东西):

更新2:

最后我一直试图用下一个代码做我正在寻找的东西,但它仍然不起作用……

ALERT_DIALOG.XML

<?xml version="1.0" enCoding="utf-8"?><ScrollVIEw xmlns:androID="http://schemas.androID.com/apk/res/androID"androID:layout_wIDth="wrap_content"androID:layout_height="250dp"><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:orIEntation="vertical"    androID:scrollbaralwaysDrawVerticalTrack="true"    androID:scrollbars="vertical">    <TextVIEw        androID:ID="@+ID/msg"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:textSize="14sp" /></linearLayout>

MYALERTDIALOG.JAVA

public class MyDialogFragment extends DialogFragment {public static MyDialogFragment newInstance(String text) {    MyDialogFragment frag = new MyDialogFragment();    Bundle args = new Bundle();    args.putString("TEXT", text);    System.out.print("Text dentro de newInstance: " + text);    frag.setArguments(args);    return frag;}@NonNull@OverrIDepublic Dialog onCreateDialog(Bundle savedInstanceState) {    String sinopsis = getArguments().getString("TEXT");    System.out.print("Text dentro de onCreateDialog: " + text);    return new AlertDialog.Builder(getActivity())            .setIcon(androID.R.drawable.ic_dialog_info)            .setTitle("Title")            .setMessage(text)            .setNegativebutton("OK",                    new DialogInterface.OnClickListener() {                        public voID onClick(DialogInterface dialog, int whichbutton) {                            dismiss();                        }                    }            ) .create();}@Nullable@OverrIDepublic VIEw onCreateVIEw(LayoutInflater inflater, @Nullable VIEwGroup container, @Nullable Bundle savedInstanceState) {    return inflater.inflate(R.layout.alert_dialog, container);}}

ActivityWhereDialogIsBeenCalled.java

........DialogFragment frag = MyDialogFragment.newInstance("MY MESSAGE");        frag.show(getSupportFragmentManager(),"TAG");...............

我的对话框显示使用DEFAulT LAYOUT(它没有scrollvIEw也没有我感兴趣的大小(只显示为默认的androID警告对话框……)

我该如何解决这个问题?我认为这很愚蠢,但令人沮丧……无论如何,谢谢!

解决方法:

您应该使用自定义对话框布局,请检查documentation.

实际上,你可以通过getDialog()调整对话框.getwindow().setLayout(wIDth,height);只需将其命名为onResume(而不是onCreateVIEw).

您的视图必须嵌套在ScrollVIEw中,请检查post.

在Dialog中读取大量文本可能很烦人,最好使用你拥有的所有像素,考虑简单的Activity / Fragment.

总结

以上是内存溢出为你收集整理的android – 如何调整AlertDialog.Builder的大小?全部内容,希望文章能够帮你解决android – 如何调整AlertDialog.Builder的大小?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1098980.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存