1

这是我的代码:

@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;
  }

在此处输入图像描述

我得到了像上面这样的输出。

  1. 我需要AlertDialog全屏显示/屏幕尺寸的 95%。
  2. 我需要处理Dialog.
  3. 如何在HorizontalScrollview中启用AlertDialog
4

3 回答 3

1

要获得滚动行为,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;
}

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

于 2011-04-07T06:54:58.873 回答
0

我不确定这一点,但您可以为对话框设置自己的布局。参考我的回答Android: Dialog dismisses without call dismiss

于 2011-04-07T06:46:15.383 回答
0

如果你想自定义一个AlertDialog你需要创建一个CustomDialog

于 2011-04-07T06:50:29.360 回答