我如何更改AlertDialog按钮面板(动作按钮后面的区域)的颜色?

问题描述 投票:0回答:1

我的应用程序显示一个AlertDialog

        page1WalkthroughDialogBuilder = new AlertDialog.Builder(activity, R.style.Widget_AppCompat_Light_ActionBar);
    page1WalkthroughDialogBuilder
            .setCancelable(false)
            .setView(page1WalkthroughDialogLayout)
            .setPositiveButton(getString(R.string.goto_next), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    page2Walkthrough.show();
                    dialog.cancel();
                }
            })
            .setNegativeButton(getString(R.string.exit_dialog), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    manager.beginTransaction().show(LaunchActivity.editProfileFragment).commit();
                    dialog.cancel();
                }
            });

    page1Walkthrough = page1WalkthroughDialogBuilder.create();

使用以下布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/rel_layout"
    android:layout_height="match_parent"
    android:background="@drawable/park_with_people"
    mlns:android="http://schemas.android.com/apk/res/android">
<TextView
    android:id="@+id/heading"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:textStyle="bold"
    android:text="@string/welcome_hdr"
    android:textSize="35sp"
    android:layout_marginTop="10dp"
    android:layout_marginStart="10dp" />

<uomini.com.wegrokstrasbourg.TextViewWithImages
    android:id="@+id/body"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_alignParentStart="true"
    android:layout_below="@+id/heading"
    android:text="@string/welcome_text"
    android:textSize="20sp"
    android:layout_marginTop="10dp"
    android:layout_marginEnd="10dp"
    android:layout_marginStart="10dp" />
</RelativeLayout>

除了按钮有白色背景外,其他所有显示都很好:

enter image description here

如何更改背景颜色?

android android-alertdialog background-color
1个回答
1
投票

您应该创建一个样式,然后将其应用于Builder构造函数:

<style name="MyTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="android:background">@color/myColor</item>
</style>

然后是:

AlertDialog alertDialog = new AlertDialog.Builder(getContext(), R.style.MyTheme)
    ...
    ...
    .create();
© www.soinside.com 2019 - 2024. All rights reserved.