DialogFragment에 Animation 지정

나고수·2022년 6월 24일
0

1일1공부

목록 보기
47/68

dialogFragment에 in.out anim을 넣어달라는 요청을 받음. 여기서는 dissolve in,out 으로..

//DialogFragment.kt

    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        val dialog = super.onCreateDialog(savedInstanceState)
        dialog.window?.requestFeature(Window.FEATURE_NO_TITLE)
        dialog.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        dialog.window?.attributes?.windowAnimations = R.style.DialogAnimation //👈 스타일 지정으로 animation 지정가능
        return dialog
    }
//style.xml

  <style name="DialogAnimation">
        <item name="android:windowEnterAnimation">@anim/dissolve_in</item>
        <item name="android:windowExitAnimation">@anim/dissolve_out</item>
    </style>
//dissolve_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true" >
    <alpha
        android:duration="400"
        android:fromAlpha="0.0"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:toAlpha="1.0" />
</set>
//dissolve_out.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true" >
    <alpha
        android:duration="400"
        android:fromAlpha="1.0"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:toAlpha="0.0" />
</set>
profile
되고싶다

0개의 댓글