对话框主题动画问题

Dialog theme animation issue

我已经使用 AlertDialog class 创建了一个对话框。使用自定义视图。我想为它设置进入和退出动画。当我尝试这样做时,该对话框将自身转换为小的黑色背景视图。如何获得具有正确视图的动画??

final AlertDialog.Builder builder = new AlertDialog.Builder(
            /*getContext()*/
            new android.support.v7.view.ContextThemeWrapper(getContext(), R.style.StyleDialog));

    View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_email, null);
    builder.setView(view);
    builder.setCancelable(false);
    alert = builder.create();
    alert.show();

这些是样式

<style name="StyleDialog" parent="@android:style/Theme.Dialog">
        <item name="android:windowAnimationStyle">@style/DialogAnimation</item>
    </style>

    <style name="DialogAnimation">
        <item name="android:windowEnterAnimation">@anim/fadein</item>
        <item name="android:windowExitAnimation">@anim/fadeout</item>
    </style>

android.support.v7.view.ContextThemeWrapperandroid.view.ContextThemeWrapper 都试过了,但没有区别。

使用 android.app.AlertDialog class.

我找到了解决方案。只需为我没有给出的布局设置背景(在我的例子中是白色)。因为当我们设置自己的样式时,它默认使用黑色背景,如果不设置样式,则默认使用白色背景。

android:background="@color/bg_white"

为了获得合适的宽度,将第一个视图的宽度设置为 match_parent。

android:layout_width="match_parent"