android - 对话框主题动画问题

标签 android android-alertdialog android-theme android-styles android-dialog

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

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

最佳答案

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

android:background="@color/bg_white"

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

android:layout_width="match_parent"

关于android - 对话框主题动画问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39919527/

相关文章:

android - 如何在 doInBackground() 时显示对话框。异步任务

android - AlertDialog源码​​中的resid >= 0x0100000是什么意思?

android - 在主题中定义 TabLayout 样式

android - 在哪里重新创建 Activity ?

java - Android 操作栏文本自定义颜色

android - 同步Android和PC的系统时钟

java - 将 byte[] 转换为 String Java Android 加密

Android Studio 列表文件方法

android: 相机 onPause/onResume 问题

android - 自定义警报对话框错误