Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - TabLayout in AndroidX

Tags:

I just tried to implement tabLayout on Android with androidX and im not able to do it.

Is tabLayout on androidX deprecated?

like image 847
Ciro González Avatar asked Oct 01 '19 01:10

Ciro González


People also ask

Can I use TabLayout without ViewPager?

These methods have a features: always attaching the "tab widget" with a ViewPager , and in order to make this requirement, we must disable swipe feature of the ViewPager . Now, with Material design, we now use TabLayout widget, which can "stand alone" to build a tab bar and do not need a ViewPager anymore.


2 Answers

You need to add material library as a dependency to build.gradle file to use TabLayout

dependencies {
    implementation 'com.google.android.material:material:1.0.0'
}

also inclue google() maven repository to the repositories section of the root build.gradle

allprojects {
    repositories {
      google()
      jcenter()
    }
}

You can read the Getting started with Material Components for Android to learn more about the library.

like image 92
Roaim Avatar answered Nov 11 '22 13:11

Roaim


TabLayout belongs to Maven artifact com.android.support:design:$version

if you want to use TabLayout in androidX you need to add material library

Ref : https://developer.android.com/jetpack/androidx/migrate

Ref : https://developer.android.com/jetpack/androidx/migrate/artifact-mappings

so you need to add implementation 'com.google.android.material:material:1.0.0' in dependency.

dependencies {
    implementation 'com.google.android.material:material:1.0.0'
}
like image 35
Ashvin solanki Avatar answered Nov 11 '22 13:11

Ashvin solanki