gpt4 book ai didi

android - 在对话框中查看太小,截断文本

转载 作者:行者123 更新时间:2023-11-29 20:47:49 36 4
gpt4 key购买 nike

我创建了一个对话框,其中显示文本的 View 似乎比对话框小,导致文本被截断。
我做错了什么?

enter image description here

String result = "This is line 1 11111111111111111111111\n" + "This is line 2 22222222222222222\n" + "This is line 3 3333333333333333333333\n" +
"This is line 4 44444444444444444444444\n" + "This is line 5 55555555555555555\n" + "This is line 6 6666666666666666666666\n" +
"This is line 7 77777777777777777777777\n" + "This is line 8 88888888888888888\n" + "This is line 9 9999999999999999999999\n" +
"This is line 1010101010101010101010101\n" + "This is line 11 1111111111111111\n" + "This is line 12 1212121212121212121212\n";

Display display = getActivity().getWindowManager().getDefaultDisplay();
int displayWidth = display.getWidth();
int displayHeight = display.getHeight();

AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder. setPositiveButton("Dismiss",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,int which) {
}
}).setIcon(android.R.drawable.ic_dialog_info);
builder.setMessage(result);
Dialog dialog = builder.setView(new View(mContext)).create();
dialog.setTitle("Details");

dialog.show();

WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
layoutParams.copyFrom(dialog.getWindow().getAttributes());
layoutParams.width = displayWidth - 50;
layoutParams.height = displayHeight - 100;

// change position of window on screen
layoutParams.x = displayWidth / 2;
layoutParams.y = (displayHeight / 2);

layoutParams.dimAmount = 0.7f; //change this value for more or less dimming

dialog.getWindow().setAttributes(layoutParams);

dialog.getWindow().addFlags (
WindowManager.LayoutParams.FLAG_DIM_BEHIND |
WindowManager.LayoutParams.FLAG_FULLSCREEN);

最佳答案

问题出在您在 alertDialog 中实现的添加的自定义 View

setView(new View(mContext))

将会发生的是,它将有一个空间用于放置 View ,从而导致内联消息被切断,因为它很长。

只需删除它或创建一个 xml 布局,将其设置为 alertDialog 的自定义 View 。

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder. setPositiveButton("Dismiss",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,int which) {
}
}).setIcon(android.R.drawable.ic_dialog_info);

builder.setView(//your xml view here);

Dialog dialog = builder.create();

TextView message = dialog.findViewById(//the id of the textview);
message.setText(result);

dialog.setTitle("Details");

dialog.show();

关于android - 在对话框中查看太小,截断文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29994665/

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