Android警告对话框在棒棒糖系统上未正确设置样式。

15

我已经尝试了一切,但无法弄清楚如何解决这个问题。

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

我甚至尝试在GitHub上使用许多材料对话框,但同样它们只在Kitkat上工作,在Lollipop上不起作用。

我正在使用带有原始Nexus映像的Nexus 5进行测试。

KITKAT与GitHub Material Dialog

enter image description here

KITKAT与原始Alert Dialog

enter image description here

LOLLIPOP与GitHub Material Dialog

enter image description here

LOLLIPOP与原始Alert Dialog

enter image description here

此外,这是安装在同一设备上但无法正常工作的GitHub库。所以这是我应用程序的问题,可能是什么呢?

enter image description here


1
好的。我找到了问题,但不确定如何修复。我在我的样式中将fitsSystemWindows设置为true。删除它后,对话框正常了。但是我的布局乱了:( - BigDX
2个回答

27

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

我在styles.xml中声明了它。

从styles.xml中删除它并将其放在我的layout中,现在它可以正常工作了。


尽管我遵循了你的建议,但在Lollipop上,我的EditText(在我设置的自定义视图内)仍然遇到了一些奇怪的样式问题。解决方法是在相关的EditText上将fitsSystemWindows设置为false。此外,在自定义视图中可能会丢失填充,如果可能的话,使用边距来解决这个问题。 - thisbytes
2
请注意,如果您将fitsSystemWindows应用于样式,并将其作为主题应用于Activity(或整个应用程序),则该属性将应用于该Activity或应用程序上的每个视图。参考:http://developer.android.com/guide/topics/ui/themes.html#ApplyingStyles。由于对话框有自己的窗口,因此如果您在Activity(或应用程序)之外有一个对话框,则会应用该属性,并且文本将扩展以适应窗口。至少,在我的情况下,我非常确定是这样的。 :) - stuckj

1

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

为了解决这个问题,我不得不将布局包装在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>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接