Android:单击按钮时如何在片段中显示带有选项卡布局的窗口(如弹出窗口)

问题描述 投票:0回答:1

我有一个片段,我需要显示一个不覆盖整个屏幕的窗口,并且我需要在该弹出窗口中显示两个选项卡。

如何在单击 myfragment 中的按钮时实现此目的

android kotlin popup android-tablayout
1个回答
0
投票

我不完全确定,但我相信这些信息可能对您有帮助。 //在onViewCtreated的片段中实现

enter code here

覆盖 fun onCreateView( 充气器:LayoutInflater,容器:ViewGroup?, 已保存实例状态:捆绑? ): 看法? { 绑定 = FragmentCalendarBinding.inflate(inflater, 容器, false) popupBinding = PopupLayoutBinding.inflate(inflater) val popupView = popupBinding.root 弹出窗口 = 弹出窗口( 弹出视图, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 真的 ) popupBinding.tabLayout.setupWithViewPager(popupBinding.viewPager) popupBinding.viewPager.adapter = YourAdapter(childFragmentManager) popupWindow.showAtLocation(视图, Gravity.CENTER, 0, 0) 返回绑定.root }

// 还创建适配器来处理不同的选项卡 在你的适配器中实现这个 在此处输入代码 重写 fun getCount(): Int { // 返回标签页数 返回2 }

override fun getPageTitle(position: Int): CharSequence? {
    // Set tab titles if needed
    return when (position) {
        0 -> "Tab 1"
        1 -> "Tab 2"
        else -> null
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.