Alexander Sloane
Alexander Sloane

Reputation: 27

Android TabLayout class not resolving

I cannot get TabLayout to resolve. I've tried implementing all the dependencies others have recommended for this issue, but it's still not working. Can anyone help? Is the issue that I'm trying to use older features alongside Androidx? Thanks

SECTION ONE: build.gradle

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.0"

    defaultConfig {
        applicationId "com.example.instagramclone"
        minSdkVersion 16
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    //Design
    implementation 'com.android.support:support-compat:30.0.0'
    implementation "com.android.support:support-core-utils:30.0.0"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.google.android.material:material:1.1.0'
    implementation 'com.github.ittianyu:BottomNavigationViewEx:2.0.4'
    implementation "com.android.support:design:30.0.0"

}

SECTION TWO: XML FILE

<merge xmlns:android="http://schemas.android.com/apk/res/android">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentTop="true">

        <com.google.android.material.appbar.AppBarLayout
            android:layout_width='match_parent'
            android:layout_height = 'wrap_content'>

            <android.support.design.widget.TabLayout
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:id="@+id/tabs"
                android:background="@drawable/white_grey_border_bottom">

            </android.support.design.widget.TabLayout>

        </com.google.android.material.appbar.AppBarLayout>

    </RelativeLayout>

</merge>

Upvotes: 1

Views: 263

Answers (2)

Samarth Gupta
Samarth Gupta

Reputation: 66

In addition to what Gabriele suggested, you can further add tabs in your XML file like

<com.google.android.material.tabs.TabLayout
         android:layout_height="wrap_content"
         android:layout_width="match_parent">

     <com.google.android.material.tabs.TabItem
             android:text="@string/tab_text"/>

     <com.google.android.material.tabs.TabItem
             android:icon="@drawable/ic_android"/>

 </com.google.android.material.tabs.TabLayout>

Or, if you want to add them programmatically, In your onCreate, do something like this,

tabLayout.addTab(tabLayout.newTab().setText("Tab 1"));
tabLayout.addTab(tabLayout.newTab().setText("Tab 2"));
tabLayout.addTab(tabLayout.newTab().setText("Tab 3"));

Upvotes: 1

Gabriele Mariotti
Gabriele Mariotti

Reputation: 364868

The support libraries v.30.0.0 don't exist.

Remove these dependencies:

//Design
//implementation 'com.android.support:support-compat:30.0.0'
//implementation "com.android.support:support-core-utils:30.0.0"
//implementation "com.android.support:design:30.0.0"

For the TabLayout add this dependency:

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

and use the class com.google.android.material.tabs.TabLayout

Upvotes: 1

Related Questions