I am getting a render problem while creating a tab layout. Refreshing the layout is also not working.can't see the preview of the design due to this.
Xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
android:layout_width="409dp"
android:layout_height="wrap_content"
android:layout_marginTop="335dp"
app:tabSelectedTextColor="@color/white"
app:tabTextColor = "@color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.tabs.TabItem
android:id="@+id/Chatsid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Chats" />
<com.google.android.material.tabs.TabItem
android:id="@+id/tabStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Status" />
<com.google.android.material.tabs.TabItem
android:id="@+id/Callid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calls" />
</com.google.android.material.tabs.TabLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Stack trace:
java.lang.NullPointerException at android.content.res.Resources_Theme_Delegate.obtainStyledAttributes(Resources_Theme_Delegate.java:74) at android.content.res.Resources$Theme.obtainStyledAttributes(Resources.java:1631) at android.content.Context.obtainStyledAttributes(Context.java:874) at android.widget.TextView.setTextAppearance(TextView.java:3965) at androidx.appcompat.widget.AppCompatTextView.setTextAppearance(AppCompatTextView.java:216) at com.google.android.material.textview.MaterialTextView.setTextAppearance(MaterialTextView.java:106) at android.widget.TextView.setTextAppearance(TextView.java:3954) at androidx.core.widget.TextViewCompat.setTextAppearance(TextViewCompat.java:289) at com.google.android.material.tabs.TabLayout$TabView.updateTab(TabLayout.java:2772) at com.google.android.material.tabs.TabLayout$TabView.update(TabLayout.java:2801) at com.google.android.material.tabs.TabLayout$TabView.setTab(TabLayout.java:2713) at com.google.android.material.tabs.TabLayout.createTabView(TabLayout.java:1673) at com.google.android.material.tabs.TabLayout.newTab(TabLayout.java:956) at com.google.android.material.tabs.TabLayout.addTabFromItemView(TabLayout.java:824) at com.google.android.material.tabs.TabLayout.addViewInternal(TabLayout.java:1730) at com.google.android.material.tabs.TabLayout.addView(TabLayout.java:1720) at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1131) at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72) at android.view.LayoutInflater.rInflate(LayoutInflater.java:1101) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088) at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1130) at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72) at android.view.LayoutInflater.rInflate(LayoutInflater.java:1101) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088) at android.view.LayoutInflater.inflate(LayoutInflater.java:686) at android.view.LayoutInflater.inflate(LayoutInflater.java:505)
Edit:-
Manifest File:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.TabLayout"
tools:targetApi="33">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
</application>
</manifest>
Build.Gradle
plugins {
id 'com.android.application'
}
android {
namespace 'com.example.tablayout'
compileSdk 33
defaultConfig {
applicationId "com.example.tablayout"
minSdk 24
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
Downgrade the material library to: implementation 'com.google.android.material:material:1.7.0'
This downgrade worked for me.