哎,造化弄人,帮一个粉丝改代码,硬是报错,改半天改不出个所以然…很是郁闷。
后来发现,是因为版本问题= =,我的版本比较低,是android包
,她的版本高,是androidx包
,这就导致依赖
导入的包不一样,并且引入Tablayout
和ViewPager
的方式也不一样了!
AndroidX中使用TabLayout
需要导入的依赖
implementation "com.google.android.material:material:1.0.0"
然后在使用时,这样使用
<com.google.android.material.tabs.TabLayout
android:id="@+id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabTextColor="#B3B3B3"
app:tabIndicatorColor="@color/colorBlue"
app:tabSelectedTextColor="@color/colorBlue"
android:background="#D5D5D5"
app:tabMode="fixed">android:layout_width=""
android:layout_height="">
</com.google.android.material.tabs.TabLayout>
<androidx.viewpager.widget.ViewPager
android:id="@+idp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</androidx.viewpager.widget.ViewPager>
完成