【问题标题】:Android alert dialog not styled properly on LollipopAndroid 警报对话框在 Lollipop 上的样式不正确
【发布时间】:2014-12-23 08:30:13
【问题描述】:

我已经尝试了一切来使它正常工作,但无法弄清楚。

我正在尝试在我的应用程序中使用警报对话框。它在 KitKat 上运行良好,但在 Lollipop 上运行良好。

我什至尝试在 GitHub 上使用许多材料对话框,它们同样适用于 Kitkat,但不适用于 Lollipop。

我正在我的 Nexus 5 上使用库存 nexus 工厂图像进行测试。

带有 GITHUB 材质对话框的奇巧

带有库存警报对话框的奇巧

带有 GITHUB 材质对话框的棒棒糖

带有股票警报对话框的棒棒糖

这也是安装在同一设备上的 github 上的库,它无法正常工作。所以这是我的应用程序造成的。会是什么

【问题讨论】:

  • 好的。如果发现问题但不确定如何解决。我在我的样式中将 fitSystemWindows 设置为 true。删除它后,对话框很好。但不是我的布局搞砸了:(

标签: android android-5.0-lollipop material-design


【解决方案1】:

我遇到了同样的问题,在我的任何 style.xml 中都没有找到任何 fitSystemWindows。

为了解决这个问题,我必须将布局包装在 FrameLayout 中,并将边距添加到布局中,如下所示:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="@dimen/dialog_margin_title"
        android:layout_marginBottom="@dimen/dialog_margin"
        android:layout_marginLeft="@dimen/dialog_margin"
        android:layout_marginStart="@dimen/dialog_margin"
        android:layout_marginRight="@dimen/dialog_margin"
        android:layout_marginEnd="@dimen/dialog_margin"
        android:orientation="vertical">

        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Please enter the email address of the person you would like to follow, this person will be notified." />

        <EditText
            android:id="@+id/editText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="textEmailAddress" />
    </LinearLayout>
</FrameLayout>

【讨论】:

    【解决方案2】:

    android:fitsSystemWindows="true" 是罪魁祸首。

    我在我的 styles.xml 中声明了它。

    从 styles.xml 中删除它并放置在我的布局中,它现在可以工作了。

    【讨论】:

    • 尽管听从了您的建议,但我的EditText(在我设置的自定义视图中)的 Lollipop 上仍然遇到一些奇怪的样式问题。解决方法是在有问题的EditText 上将fitsSystemWindows 设置为false。此外,自定义视图中的填充可能会丢失,尽可能使用边距来解决问题。
    • 仅供参考。如果您将 fitSystemWindows 应用到一种样式,然后将其作为主题应用于 Activity(或整个应用程序),那么该属性将应用于该 Activity 或应用程序的每个视图。参考:developer.android.com/guide/topics/ui/…。由于对话框有自己的窗口,如果您有一个关闭活动(或应用程序)的对话框,它将应用该属性并且文本将扩展以适合窗口。至少,我很确定这发生在我的案例中。 :)
    猜你喜欢
    • 2015-09-05
    • 1970-01-01
    • 2016-04-05
    • 1970-01-01
    • 1970-01-01
    • 2019-01-27
    • 1970-01-01
    • 2011-02-01
    • 1970-01-01
    相关资源
    最近更新 更多