我已经使用 AlertDialog
类创建了一个对话框。使用自定义 View 。我想为它设置进入和退出动画。当我尝试这样做时,该对话框将自身转换为小的黑色背景 View 。如何获得具有正确 View 的动画??
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.ContextThemeWrapper
和 android.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/