Android开发——错误:AndroidX使用Tablayout无法调用,报错

哎,造化弄人,帮一个粉丝改代码,硬是报错,改半天改不出个所以然…很是郁闷。
后来发现,是因为版本问题= =,我的版本比较低,是android包,她的版本高,是androidx包,这就导致依赖导入的包不一样,并且引入TablayoutViewPager的方式也不一样了!
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>

完成

发布了230 篇原创文章 · 获赞 250 · 访问量 28万+

猜你喜欢

转载自blog.csdn.net/weixin_42247720/article/details/103755176