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

时间:2015-02-19 14:53:30

标签: android android-layout

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

但是,我找不到一个好的风格,让我的按钮看起来像“公司”一样,使用其他对话框中的按钮here is a link to a screenshot of the current design以及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>

我感谢任何帮助。谢谢!

2 个答案:

答案 0 :(得分:1)

您可以使用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>

答案 1 :(得分:0)

您还可以使用此库https://github.com/afollestad/material-dialogs,以便在所有Android版本中使用Material Design主题对话框