android - 如何在 Android 中设置 Alert Dialog 的高度和宽度?

标签 android fullscreen android-alertdialog horizontal-scrolling

这是我的代码:

@Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = this;    

    AlertDialog alertChoice = new AlertDialog.Builder(context).create();
    alertChoice.setTitle("Title");
    alertChoice.setView(ViewDialogScreen("Test"));    
    alertChoice.show();    
  }
  private View ViewDialogScreen(String strText) {
    LinearLayout llay = new LinearLayout(context);
    llay.setLayoutParams(new LayoutParams(320, 400));
    TextView tv = new TextView(context);
    tv.setText(strText);
    llay.addView(tv);
    return llay;
  }

enter image description here

我得到了如上的输出。

  1. 我需要以全屏/屏幕大小的 95% 显示 AlertDialog
  2. 我需要处理 Dialog 中的更多字段。
  3. 如何在 AlertDialog 中启用 Horizo​​ntalScrollview

最佳答案

要获得滚动行为,请将周围的 ScrollView 添加到您的布局中,这将使您的 ViewDialogScreen 方法变成这样:

private View ViewDialogScreen(String strText) {
    ScrollView scroll = new ScrollView(context);
    scroll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    LinearLayout llay = new LinearLayout(context);
    llay.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    TextView tv = new TextView(context);
    tv.setText(strText);
    scroll.addView(llay);
    llay.addView(tv);
    return scroll;
}

现在尝试添加更多字段,它应该会滚动。

关于android - 如何在 Android 中设置 Alert Dialog 的高度和宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5576991/

相关文章:

android - 制作一个 Android Studio JNI 静态库以供 JNI 读取

安卓错误 : Cannot recover key

cocoa - NSStatusBar 隐藏在 Mac OS X Lion 中

iphone - Safari 移动版全屏

java - 如何更改 AlertDialog View 背景颜色?

java - 如何在android中检查电子邮件格式是否有效

java - 修改数组中单个元素的值-firestore

Java ScreenManager,setVisible 不起作用,bufferstrategy 在全屏上丢失

java - 警报对话框的按钮被切断

android - 什么是 android.R.id.message?