AlertDialog background color issue
I have an Android AlertDialog XML layout that in the interest of better visibility sets the background to white and the textColor to black. This works fine until I remove the android:text="Hello World" entry and try to setMessage in Java to something meaningful. The meaningful message gets set and displayed fine but I lose the white background with black text... Can anybody help explain what's going on here (starting to pull my hair out!)? I have included the code below.
<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;
}
How to change dialog background color programmatically? has the answer.
You will have to extend the layout class to use a custom theme, as described in this tutorial: http://blog.androgames.net/10/custom-android-dialog/
精彩评论