How to use TabLayout with ViewPager2 in Android

You have to use this TabLayoutMediator that mimics tabLayout.setupWithViewPager() and sets up the ViewPager2 with Tablayout. Otherwise, you will have to write your own adapter that will combine both parties. Its code will look like this in Kotlin TabLayoutMediator(tabLayout, viewPager) { tab, position -> tab.text = tabTitles[position] }.attach()

Crash on Android 10 (InflateException in layout/abc_screen_simple line #17)

Update Calligraphy to newest version to solve this problem: Link: https://github.com/InflationX/Calligraphy/issues/35 More specifically, both Calligraphy and ViewPump need to be updated: implementation ‘io.github.inflationx:calligraphy3:3.1.1’ implementation ‘io.github.inflationx:viewpump:2.0.3’ Migrating from Calligraphy 2 to 3 requires some code changes; see examples in Calligraphy 3 README.

BottomSheetBehavior not in androidX libraries

It turns out that the refactor tool in Android Studio Refactor > Migrate to AndroidX didn’t correctly migrate the XML for the BottomSheetBehaviour. The old location was android.support.design.widget.BottomSheetBehavior, and was not modified by the migration tool. The original XML was: <fragment android:id=”@+id/player_bottom_sheet_fragment” android:name=”app.rxsongbrowsertrials.ui.player.PlayerToggleFragment” android:layout_width=”match_parent” android:layout_height=”match_parent” app:behavior_hideable=”false” app:behavior_peekHeight=”56dp” app:layout_behavior=”android.support.design.widget.BottomSheetBehavior” /> The new location is com.google.android.material.bottomsheet.BottomSheetBehavior, so … Read more

AndroidX:Appcompat I:art error android.view.View$OnUnhandledKeyEventListener

As A.L.Flanagan mentioned in a comment the problem is that android.support.v4.view.ViewCompat does not implement View.OnUnhandledKeyEventListener in the new androidx package structure and only implements it starting on API 28 in the support lib structure (at least in version 28.0.0). Therefore the warning appears on devices with API <28 and does not appear on those >=28. … Read more

The given artifact contains a string literal with a package reference ‘android.support.v4.content’ that cannot be safely rewritten. for androidx

New correct answer: Butterknife 10.0.0 added support for AndroidX. dependencies { implementation ‘com.jakewharton:butterknife:10.0.0’ annotationProcessor ‘com.jakewharton:butterknife-compiler:10.0.0’ } Old answer for Butterknife < 10.0.0: Try blacklisting butterknife from the jetifier: gradle.properties file: android.jetifier.blacklist = butterknife.*\\.jar You need to be on the 3.3.0-rc1 of the AGP and the 1.3.0 version of the Kotlin Gradle plugin: buildscript { repositories … Read more

What is Jetifier?

Assuming that you are familiar with AndroidX. If not, please see @this post. Jetifier will convert support libraries of all your dependencies to AndroidX automatically, if you don’t set it to true then your project will have both, the support (got deprecated after 28.0.0 version) and AndroidX package, which is redundant. For Example If you … Read more

how to get viewModel by viewModels? (fragment-ktx)

Atlast we we have got stable version. After moving to implementation ‘androidx.fragment:fragment-ktx:1.1.0’ i faced another issue. ###Compiler Error: Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6 ###build.gradle (Module:app) compileOptions { sourceCompatibility = 1.8 targetCompatibility = 1.8 } kotlinOptions { jvmTarget = “1.8” } reference After … Read more

Proper implementation of ViewPager2 in Android

UPDATE 7 Check : Migrate from ViewPager to ViewPager2 Check : Create swipe views with tabs using ViewPager2 UPDATE 6 Check out my answer if you want to implement Carousel using View Pager2 UPDATE 5 How to use TabLayout with ViewPager2 SAMPLE CODE Use below dependencies implementation ‘com.google.android.material:material:1.1.0-alpha08’ implementation ‘androidx.viewpager2:viewpager2:1.0.0-beta02’ SAMPLE CODE XMl layout <?xml … Read more