java对话框大小设置,如何调整AlertDialog.Builder的大小?

I'd like to resize my AlertDialog.Builder but I didn't find any resolution on this website, I tried everything I saw on questions like this one but seems older than I'm looking for, The code I'm watching doesn't work right now...

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

}

});

}

}

I tried to become AlertDialog.Builder to AlertDialog to resize it, but just displays a black square without data.

QUESTION: What should I do to make an AlertDialog.Builder with a large text? (need to scroll that sure, because I don't want to make the dialog as big as my screen)

UPDATED:

What I want is something like this, I HAVE TO CHANGE THE TEXT by Bundle, I call the AlertDialog from my AppCompatActivity which uses FrameLayout (I don't know what kind of Dialog it should be to cover what I need):

20c418e87129a71f847db16c9f548f6c.png

UPDATED 2:

Finally I've been trying to do what I'm looking for with the next code, but it still doesn't work...

ALERT_DIALOG.XML

android:layout_width="wrap_content"

android:layout_height="250dp">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="vertical"

android:scrollbarAlwaysDrawVerticalTrack="true"

android:scrollbars="vertical">

android:id="@+id/msg"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textSize="14sp" />

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

@Override

public 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

@Override

public 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");

...............

My dialog appears using DEFAULT LAYOUT (It doesn't have scrollview nor my interested size (just shows as default android alert dialog...)

How can I resolve this question? I think that's silly, but it's frustating... Thanks anyway!

解决方案

You should use custom dialog layout, check documentation.

Actually, you can resize dialog by getDialog().getWindow().setLayout(width, height); just call it onResume (not onCreateView).

Your view must be nested inside of a ScrollView, check post.

Reading huge amount of text in a Dialog can be annoying, it's better to use all pixels you have, consider simple Activity/Fragment.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值