对AlertDialog的入口和出口进行动画处理

编程入门 行业动态 更新时间:2024-10-12 10:23:12
本文介绍了对AlertDialog的入口和出口进行动画处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我必须在 AlertDialog 进入时滑动,而在它被关闭时滑出它,但它没有动画。

I have to slide in an AlertDialog when it enters and slide it out when it is dismissed, but it is not animating.

那么我如何使动画起作用?

So how do I get the animation to work ?

这里是我所拥有的,

public class SlideDialogFragment extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { return new AlertDialog.Builder(new ContextThemeWrapper(getActivity(),R.style.SlidingDialog)) .setTitle("Sliding dialog") .create() }

themes.xml

<?xml version="1.0" encoding="utf-8"?> <resources xmlns:android="schemas.android/apk/res/android"> <style name="SlidingDialog" parent="@android:style/Theme.DeviceDefault.Dialog"> <item name="android:windowAnimationStyle">@style/SlidingDialogAnimation</item> </style> <style name="SlidingDialogAnimation"> <item name="android:windowEnterAnimation">@android:anim/slide_in_left</item> <item name="android:windowExitAnimation">@android:anim/slide_out_right</item> </style> </resources>

我提到了太多资源,似乎没有一个合适的方法对我有用的,也许是我丢失了一些东西

I have referred too many resources and there doesn't seem to be a single proper way to do this that works for me, may be I am missing something

我正在使用

  • Android ICS
  • 应用程序是为API 15+构建的

以下是一些相关资源我无法从

Here are some related resources that I couldn't get the answer from

  • 动画后关闭对话框动画片段
  • groups.google/d/msg/android-developers/0oCWqQC4Pww/CmUM7iNHUggJ
  • groups.google/d/msg/android-developers/a2pUV0Sigf4/WiJNg_vMQWWJ
  • https:// sta ckoverflow/a/3870997/492561
  • Animate a dialog fragment on dismiss
  • groups.google/d/msg/android-developers/0oCWqQC4Pww/CmUM7iNHUggJ
  • groups.google/d/msg/android-developers/a2pUV0Sigf4/WiJNg_vMQWwJ
  • stackoverflow/a/3870997/492561
推荐答案

// Declare a Builder. AlertDialog.Builder builder = new AlertDialog.Builder(context); // You can even inflate a layout to the AlertDialog.Builder, if looking to create a custom one. // Add and fill all required builder methods, as per your need. // Now create object of AlertDialog from the Builder. final AlertDialog dialog = builder.create(); // Let's start with animation work. We just need to create a style and use it here as follows. if (dialog.getWindow() != null) dialog.getWindow().getAttributes().windowAnimations = R.style.SlidingDialogAnimation; dialog.show();

关于样式,我使用了与问题中相同的样式(在styles.xml中)。

Regarding Style, I used the same style as used in question (in styles.xml).

<style name="SlidingDialogAnimation"> <item name="android:windowEnterAnimation">@android:anim/slide_in_left</item> <item name="android:windowExitAnimation">@android:anim/slide_out_right</item> </style>

但是您可以通过将动画XML文件放置在res / anim文件夹中来使用任何其他自定义文件。

But you can use any other custom files by placing an animation XML file in the res/anim folder.

谢谢。

更多推荐

对AlertDialog的入口和出口进行动画处理

本文发布于:2023-11-25 20:33:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631248.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:入口   动画   AlertDialog

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!