【问题标题】:Dialog theme animation issue对话框主题动画问题
【发布时间】:2016-10-07 14:22:03
【问题描述】:

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

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 android-alertdialog android-theme android-styles android-dialog


    【解决方案1】:

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

    android:background="@color/bg_white"
    

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

    android:layout_width="match_parent"

    【讨论】:

      猜你喜欢
      • 2017-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-05
      • 1970-01-01
      • 2022-09-08
      相关资源
      最近更新 更多