Android alert dialog not styled properly on Lollip

2019-01-24 03:50发布

问题:

I have tried everything to get this working and cannot figure it out.

I am trying to use an alert dialog im my app. It works fine on KitKat but not on Lollipop.

I have even tried using many material dialogs on GitHub and again they work on Kitkat but not on Lollipop.

I am testing on my Nexus 5 with stock nexus factory image.

KITKAT WITH GITHUB MATERIAL DIALOG

KITKAT WITH STOCK ALERT DIALOG

LOLLIPOP WITH GITHUB MATERIAL DIALOG

LOLLIPOP WITH STOCK ALERT DIALOG

Also this is the library on github installed on the same device its not working on. So its something about my app that is causing this. what could it be

回答1:

android:fitsSystemWindows="true" was the culprit.

I had that declared in my styles.xml.

Removed it from styles.xml and placed in my layout and it working now.



回答2:

I had the same problem and didn't find any fitsSystemWindows on any of my styles.xml.

To solve it i had to wrap the Layout in a FrameLayout and add the margins to the Layout like this:

<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>