Android tabs

Since google has stopped release of new android.support libraries you have to migrate to latest androidx artifact. you can do that by simply using Refactor -> migrate to androidx. You can check official documentation for more details.

material tabs are introduced in android lollipop, but using androidx you can make it backward compatible way back to android gingerbread.

First thing we need to do is to add material library inside app level build.gradle file(app->build.gradle). Its an alternative to support.design library. for that paste the below code inside build.gradle file

https://gist.github.com/184b2b56671d5465dfb93bdcfdf855ce

Then we need to hide the default actionbar. for that navigate to app->src->main->res->values->styles.xml

Now change the parent theme Theme.AppCompat.Light.DarkActionBar to Theme.AppCompat.Light.NoActionBar

https://gist.github.com/jobinjj/68b3848bb80856951b2317f279862329

Run the app and check if actionbar is present. If not, theme has been successfully changed.

Changing layout files

Open activity_main.xml and paste below code. It will create an interface that has a tab,toolbar and a viewpager.

Now we need to create three fragments, FragmentOne,FragmentTwo and FragmentThree.

Create a fragment by rightclicking on package and new->fragment->Fragment(Blank). Make sure to uncheck fragment factory methods and interface callbacks checkboxes.

Now you should have something like above

Similarly create two more fragments.

Open MainActivity.java and add below code .

Last updated