2012-08-05 78 views
0

我想提出一个警告对话框中存在的警告对话框更多的文本的application.Because,我希望把垂直滚动条在dialog.I已经尝试了许多选项的警报,但没有什么是working.Please告诉我如何解决这个问题。这是代码:添加垂直滚动条到一个警告对话框

AlertDialog.Builder HelpOnButtonDialog ; 
     HelpOnButtonDialog = new AlertDialog.Builder(this); 
     TextView HelpOnButtonView = new TextView(this); 
     HelpOnButtonView.setSingleLine(false); 
     HelpOnButtonView.setTextColor(getResources().getColor(R.color.dark_green)); 
     HelpOnButtonView.setText("hello"); 
     Button HelpOnButton = new Button(this); 
     HelpOnButton.setHeight(20); 
     HelpOnButton.setWidth(20); 
     HelpOnButton.setText("Ok"); 
     HelpOnButton.setOnClickListener(HelpOnButtonClickListener); 
     LinearLayout linearLayout = new LinearLayout(this); 
     linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, 
       LinearLayout.LayoutParams.WRAP_CONTENT)); 
     linearLayout.setOrientation(1); 
     linearLayout.setBackgroundColor(getResources().getColor(R.color.black)); 
     linearLayout.addView(HelpOnButtonView); 
     linearLayout.addView(HelpOnButton); 

     ScrollView sv = new ScrollView(this); 
     sv.pageScroll(0); 
     sv.setBackgroundColor(0); 
     sv.setScrollbarFadingEnabled(true); 
     sv.setVerticalFadingEdgeEnabled(false); 
     sv.addView(linearLayout); 
     alertHelp = HelpOnButtonDialog.create(); 
     alertHelp.setView(sv); 
     alertHelp.show(); 

回答

3

创建一个自定义对话框,您可以自定义它,如你所愿。在对话框中布局的xml文件

环绕你的RelativeLayout或LinearLayout中与滚动像下面的代码

<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:scrollbars="vertical" 
    android:scrollbarAlwaysDrawVerticalTrack="true" 
    android:orientation="vertical" 
    android:layout_weight="1"> 

    <!--Your other text views, buttons... etc surrounded by RelativeLayout 
or LinearLayout goes here--> 

</ScrollView> 

当其含量超过dlalog箱尺寸会显示滚动条。 希望这将帮助你:)

+0

如何滚动条的颜色设置? – NukeouT 2015-08-20 20:32:06