AlertDialog背景颜色问题

时间:2011-05-13 16:35:41

标签: android android-layout alertdialog

我有一个Android AlertDialog XML布局,为了更好的可见性,将背景设置为白色,将textColor设置为黑色。这工作正常,直到我删除android:text =“Hello World”条目并尝试将Java中的setMessage转换为有意义的东西。有意义的消息设置和显示正常,但我失去了黑色文本的白色背景......任何人都可以帮助解释这里发生了什么(开始拉我的头发!)?我已经包含了以下代码。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollview_1" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"
android:background="@color/white">
<LinearLayout 
    android:id="@+id/layout_root"
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="10dp">
    <TextView android:id="@+id/help_text" 
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="Hello World" 
        android:textSize="20sp" 
        android:textColor="@color/black">
    </TextView>
</LinearLayout>

private AlertDialog showHelp() {

    AlertDialog alertDialog = new AlertDialog.Builder(Game.this).create();
    View diagview = LayoutInflater.from(getBaseContext()).inflate(R.layout.help_dialog,    
                                            (ViewGroup) findViewById(R.id.layout_root));
    alertDialog.setTitle("Help...");
    alertDialog.setView(diagview);
    alertDialog.setIcon(R.drawable.ic_help);
    alertDialog.setMessage(this.getString(help[helpIndex]));
    alertDialog.setIcon(R.drawable.ic_help);
    alertDialog.setButton("Close", new DialogInterface.OnClickListener() {

    public void onClick(DialogInterface dialog, int which) {
        } });

    alertDialog.show();
    return alertDialog;
}

1 个答案:

答案 0 :(得分:1)

How to change dialog background color programmatically?有答案。

您必须扩展布局类以使用自定义主题,如本教程中所述: http://blog.androgames.net/10/custom-android-dialog/

相关问题