我必须在 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的入口和出口进行动画处理
发布评论