Android 与自定义布局按钮样式appcompat的对话

Android Dialogue with custom layout button style appcompat

目前正在开发一个甚至可以与 Android 一起使用的应用程序 2.2 我使用支持库及其 AppCompat 主题来设计我的 UI。虽然大多数 UI 工作正常,但我有一个带有自定义布局的 AlertDialog,包括两个自定义按钮,这是必需的,因为按下其中一个按钮时不应立即关闭对话框。

但是,我找不到合适的样式来使我的按钮看起来 "corporate" 与其他对话框中的按钮相同(here is a link to a screenshot of the current design as well as one with the desired design;我目前没有足够的声誉来发布图像)。您可以在下面找到我定义按钮的布局(出于测试目的,我使用了两种不同的样式)。

<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/txtPassword">

            <Button android:id="@+id/btnCancelLogin"
                style="@style/Theme.AppCompat.Dialog"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:text="@string/btnCancel"/>

            <Button android:id="@+id/btnLogin"
                style="@style/Theme.AppCompat.Dialog"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:text="@string/btnEnterPassword"/>

</LinearLayout>

感谢任何帮助。谢谢!

您可以使用 buttonBar 样式来实现此目的。只需将此样式添加到您的布局项目

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/txtPassword"
        style="?attr/buttonBarStyle">

        <Button android:id="@+id/btnCancelLogin"
            style="?attr/buttonBarButtonStyle"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:text="@string/btnCancel"/>

        <Button android:id="@+id/btnLogin"
            style="?attr/buttonBarButtonStyle"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:text="@string/btnEnterPassword"/>

    </LinearLayout>

您也可以使用此库 https://github.com/afollestad/material-dialogs 使您能够在 Android

的所有版本中使用 Material 设计主题对话框