如何在anko中创建标签视图

我想要创建时间表应用程序,但是我在创建选项卡式视图时遇到了问题,如图片中所示。 我试图使用tabhost和tabwidget,但没有效果。 是否有可能,使用anko构建tabview? 图片

您必须通过使用带有ViewPager的TabLayout使用片段来创建它。 这里是Kotlin代码片段

// Create the adapter that will return a fragment for each of the three // primary sections of the activity. mPagerAdapter = PageAdapter(supportFragmentManager, this) // Set up the ViewPager with the sections adapter. mViewPager = findViewById<ViewPager?>(R.id.container) mViewPager!!.adapter = mPagerAdapter val tabLayout = findViewById<View>(R.id.tabs) as TabLayout tabLayout.setupWithViewPager(mViewPager) // set icons tabLayout.getTabAt(0)!!.setIcon(R.drawable.ic_call) tabLayout.getTabAt(1)!!.setIcon(R.drawable.ic_fav) tabLayout.getTabAt(2)!!.setIcon(R.drawable.ic_contacts)