1

我已经实现Viewpager2并且其中有 2 个片段,每当我打开键盘时,就会调用onPageSelectedofViewPager2.OnPageChangeCallback()并且所选页面首先显示到第一个,然后切换到第二个

viewPager.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
        override fun onPageSelected(position: Int) {
            super.onPageSelected(position)
            selectedPos = position
            if (position == 1) {
                ivBackVp.visibility = View.VISIBLE
                progress.progress = 100
                if (userType == Const.TYPE_PARENT) {
                    tvStepDescription.text = getString(R.string.create_profile_step_two)
                } else {
                    tvStepDescription.text = getString(R.string.create_profile_step_two_child)
                }
                tvNext.text = getString(R.string.done)
            } else {
                ivBackVp.visibility = View.GONE
                progress.progress = 50
                if (userType == Const.TYPE_PARENT) {
                    tvStepDescription.text = getString(R.string.create_profile_step_one)
                } else {
                    tvStepDescription.text = getString(R.string.create_profile_step_one_child)
                }
                tvNext.text = getString(R.string.next)
            }
        }
    })

我试过设置configChanges to keyboard in the manifest,但也失败了。请帮助我解释为什么它必须调用的合乎逻辑的原因,以及我应该怎么做才能解决这个问题。

4

0 回答 0