TabLayout:layout 标记的意外隐式转换为 TableLayout

Unexpected implicit cast to TabLayout:layout tag was TableLayout

参考了几乎所有类似类型的问题;未找到答案。

注意:我在第 26 行有一个错误

Cannot resolve method'setUpWithViewPager(androidx.viewpager.widget.ViewPager)'

在这里,在 line 5 我导入了 TabLayoutNOT TableLayout
line 16 处编写代码时出现意外错误,悬停时显示

Unexpected implicit cast to TabLayout:layout tag was TableLayout

当我将 TabLayout 更改为 TableLayout line 16 处的错误消失 BUT 第 26 行的错误仍然存​​在,并且根据
我需要将 Table 布局更改为选项卡 Layout.Which 将我带到 "square 1 again"。

这是我的 XML 文件 activity_intro

Cannot resolve method'setUpWithViewPager(androidx.viewpager.widget.ViewPager)'

正确的方法是:

tabLayout.setupWithViewPager(viewPager);

而不是

tabLayout.setUpWithViewPager(viewPager);

implicit cast to TabLayout:layout tag was TableLayout

在您的布局中,您必须使用以下组件:

  <com.google.android.material.tabs.TabLayout
      ...>
     <com.google.android.material.tabs.TabItem/>

  </com.google.android.material.tabs.TabLayout>

你调用错方法了,应该是

tabIndicator.setupWithViewPager(screenPager);