Creating a Tab Layout with Icons & Fragments in Android Studio Tutorial  (Kotlin)

Creating a Tab Layout with Icons & Fragments in Android Studio Tutorial (Kotlin)

Indently

4 года назад

41,390 Просмотров

Hey guys! Make sure you don't pick all the same colours like I did in the video, it looks much better if you have 3 seperate colours for this. Other than that you can find the dependency down below:

Material Dependency: implementation 'com.google.android.material:material:1.1.0'

Тэги:

#android_studio #code #coding #program #programming #tutorials #android #studio #java #kotlin #python #c# #how_to #app #applications #developer #developement #learn_coding #learn_programming #free
Ссылки и html тэги не поддерживаются


Комментарии:

ItzMeSkySurvival
ItzMeSkySurvival - 11.06.2023 12:57

I have managed to get this to work so I thought I should mention how I did this. Firstly really great video. This is solution for viewPager error around 10 mins into video. Similar to adding implementation you need to add the following in same build.gradle, this is all for kotlin ,
viewBinding {
enabled = true
}
then make sure you sync, then in Mainactivity.kt

private lateinit var binding: ActivityMainBinding


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)

setUpTabs()

}

private fun setUpTabs(){
val adapter = ViewPagerAdapter(supportFragmentManager)
adapter.addFragment(HomeFragment(), "Home")
adapter.addFragment(FavouritesFragment(), "Favourites")
adapter.addFragment(SettingsFragment(), "Settings")

binding.viewPager?.adapter = adapter
binding.tabs?.setupWithViewPager(binding.viewPager)

Ответить
Stéphane Kamga
Stéphane Kamga - 27.04.2023 13:43

thanks 👍

Ответить
Jabi
Jabi - 13.12.2022 23:36

for the erro of not finding the viewPager.adapter = adapter its because you need binding to do so, just write binding.viewPager.adapter = adapter

Ответить
sarfaraz ahmed
sarfaraz ahmed - 09.10.2022 19:39

R.drawable is already present in android studio use your custom Icons.

Ответить
Neville Valentine
Neville Valentine - 10.08.2022 11:35

Hey ...when I type in the viewpager I'd on the mainActivity part it doesn't recognize it from the xml😢

Ответить
Muhammd Shah
Muhammd Shah - 14.06.2022 15:16

thank you

Ответить
Farid Cenreng-1005
Farid Cenreng-1005 - 03.05.2022 13:55

i get this error, "Classifier 'HomeFragment' does not have a companion object, and thus must be initialized here" is it really okay to just delete companion object in fragment?

Ответить
Mustafo
Mustafo - 26.03.2022 18:45

Thank you bro!!!

Ответить
ABHILASH RAJAGOPAL
ABHILASH RAJAGOPAL - 20.03.2022 03:57

Thank you for a nice content.

Ответить
Andrew Belozertsev
Andrew Belozertsev - 25.02.2022 15:08

Everything did like in a video. IDE dont show any problems. But app is crashes when started without any error. What i've done wrong?

Ответить
Marc
Marc - 27.01.2022 15:11

Mine doesn't accept neither "ViewPagerAdapter" , nor "SupportFragmentManager". How can I do it with sectionsPagerAdapter and supportFragmentManager ?

Ответить
Tomas Menniti
Tomas Menniti - 28.11.2021 17:54

didn´t work >:(

Ответить
Surya
Surya - 29.08.2021 10:15

icons are not showing in mine? anyone plz help

Ответить
Custom Dev
Custom Dev - 02.08.2021 17:29

Thanks helped a lot!

Ответить
Lay Ly
Lay Ly - 11.06.2021 13:40

Hello guys why my tab title didn't show in my tablayout?

Ответить
YOU SSH
YOU SSH - 30.04.2021 18:22

it is ridiculous how overcomplicated android development is, i mean jesus, in web development with html css and js it takes like 10 minutes, and it actually is intuitive

Ответить
Bachtiar Fariz
Bachtiar Fariz - 26.04.2021 15:35

hi i really needs help, my code didnt recognized the viewPager id. what should i do?

Ответить