Animate a custom dialog, custom dialog Animation

Source: Internet
Author: User
Inside res/style.xml<style name="AppTheme" parent="android:Theme.Light" /><style name="PauseDialog" parent="@android:style/Theme.Dialog">    <item name="android:windowAnimationStyle">@style/PauseDialogAnimation</item></style><style name="PauseDialogAnimation">    <item name="android:windowEnterAnimation">@anim/fadein</item>    <item name="android:windowExitAnimation">@anim/fadeout</item></style>Inside anim/fadein.xml<alpha xmlns:android="http://schemas.android.com/apk/res/android"    android:interpolator="@android:anim/accelerate_interpolator"    android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="500" />

Inside anim/fadeut.xml<alpha xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/anticipate_interpolator" android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="500" />MainActivityDialog imageDiaglog= new Dialog(MainActivity.this,R.style.PauseDialog);

 

Http://stackoverflow.com/questions/4817014/animate-a-custom-dialog

 
<?xml version="1.0" encoding="utf-8"?><resources>    <style name="PauseDialog" parent="@android:style/Theme.Dialog">        <item name="android:windowAnimationStyle">@style/PauseDialogAnimation</item>    </style>    <style name="PauseDialogAnimation">        <item name="android:windowEnterAnimation">@anim/spin_in</item>        <item name="android:windowExitAnimation">@android:anim/slide_out_right</item>    </style></resources>
 

 

The windowEnterAnimation is one of my animations and is located in res\anim. The windowExitAnimation is one of the animations that is part of the Android SDK.Then when I create the Dialog in my activities onCreateDialog(int id) method I do the following.Dialog dialog = new Dialog(this, R.style.PauseDialog);// Setting the title and layout for the dialogdialog.setTitle(R.string.pause_menu_label);dialog.setContentView(R.layout.pause_menu);Alternatively you could set the animations the following way instead of using the Dialog constructor that takes a theme.Dialog dialog = new Dialog(this);dialog.getWindow().getAttributes().windowAnimations = R.style.PauseDialogAnimation;

 

Animate a custom dialog, custom dialog Animation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.