4

我有一个警报对话框工作正常。它使用简单的 .XML 布局进行扩展。TextView 使用 HTML 格式的字符串设置。到目前为止,一切都很好。问题是当 .setView() 太大时,对话框按钮会消失!!! 他们在哪里?告诉他们我爱他们!:'(

当.setView () 太大时,如何防止警报对话框按钮消失

截图:

1) 小,没问题!

2) 大,我的按钮在哪里???

这是 MainActivity.java 中的 java 代码:

AlertDialog.Builder dialogBox = new AlertDialog.Builder(this);
dialogBox.setTitle("Title");
dialogBox.setMessage("Subtitle");

// INFLATING THE LAYOUT
View alertLayout = getLayoutInflater().inflate( R.layout.scrollable, null );
TextView textMsg = (TextView)alertLayout.findViewById(R.id.textMsg);
textMsg.setText(Html.fromHtml("html string"));
dialogBox.setView(alertLayout);

// MY BUTTONS
dialogBox.setNeutralButton("Neutral", null);
dialogBox.setPositiveButton("Positive", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int id) {
        // Positive code
    }
});
dialogBox.show();

这是 scrollable.xml 文件:

<?xml version="1.0" encoding="utf-8"?>

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingLeft="20dp"
        android:paddingRight="20dp">
        
        <TextView
            android:id="@+id/textMsg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Dynamic HTML text."
            android:textSize="20sp" />
            
    </LinearLayout>
</ScrollView>

4

0 回答 0