滑入对话框片段

时间:2019-04-27 09:01:28

标签: android kotlin android-animation

我有一个自定义DialogFragment

class CompactPickerFragment : DialogFragment()

默认情况下,它会淡入,我想使其从底部滑入。

我尝试了以下操作(除了在堆栈溢出时找到的所有内容):

首先定义如下样式:

<style name="DialogTheme" parent="Some parent, I've tried different parents here"> //
    <item name="android:windowEnterAnimation">@anim/slide_in_left</item>
    <item name="android:windowExitAnimation">@anim/slide_out_right</item>
</style>

滑动片段时,幻灯片动画可在应用程序的其他部分起作用。通过多种方式设置此主题:

class CompactPickerFragment : DialogFragment() {

    // Attempt 1
    override fun getTheme() = R.style.DialogTheme

   // Attempt 2
    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {         
       val builder = AlertDialog.Builder(activity!!, R.style.DialogTheme)
        return builder.create()
   }

    // Attempt 3
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setStyle(STYLE_NO_FRAME, R.style.DialogTheme)

roughylu的这些尝试都给出了“无变化”-“有变化”的图片(并且没有动画发生):

beforeafter

我还尝试设置了一个输入横断面,但没有设法做任何事情:

private fun ShowPicker() {
    val slide = Slide()
    slide.duration = 1000
    slide.slideEdge = Gravity.BOTTOM
    slide.mode = MODE_IN
    val dialog = CompactPickerFragment.newOperandInstance()
    dialog.enterTransition = slide
    dialog.show(fragmentManager, CompactPickerFragment.TAG)
}

如何为自定义对话框片段提供过渡/动画?

1 个答案:

答案 0 :(得分:0)