Android

[Android] Dialog Animation

HAINIX_X 2020. 6. 2. 17:25
반응형

다이얼로그를 밋밋하게 띄우는 것보다 애니메이션을 줘서 사용자가 봤을 때 보다 더 부드러운 화면을 주게 된다.

 

1. 다이얼로그 띄울 activity

Dialog dialog = new Dialog(this, android.R.style.Theme_Black_NoTitleBar);
dialog.getWindow().getAttribute().windowAnimation = R.style.AnimationPopupStyle;

 

2. style에 AnimationPopupStyle 추가

<style name="AnimationPopupStyle">
    <item name="android:windowEnterAnimation">@anim/open</item>
    <item name="android:windowExitAnimation">@anim/close</item>
</style>

 

3. res 에 anim 폴더 생성 후 open.xml / close.xml 추가

- open.xml

<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <alpha
        android:duration="500"
        android:fromAlpha="0.0"
        android:toAlpha="1.0" />
</set>

- close.xml

<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <alpha
        android:duration="500"
        android:fromAlpha="1.0"
        android:toAlpha="0.0" />
</set>

 

반응형