【问题标题】:AlertDialog background color issueAlertDialog 背景颜色问题
【发布时间】:2011-05-13 16:35:41
【问题描述】:

我有一个 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;
}

【问题讨论】:

    标签: android android-layout android-alertdialog


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多