I've noticed the preview crashing on many PCs not just mine, but the last problem I'm experiencing is when I add a TabItem inside a TabLayout, and I can't find any solution. I've tried the following:
It might be something dumb that I forgot but right now I can't think of anything. Here's my XML code:
<?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=".ui.AdminActivity">
<com.google.android.material.tabs.TabLayout
android:id="@+id/adminTab"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tabIndicatorColor="@color/befc_blue"
app:tabSelectedTextColor="@color/befc_blue">
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:icon="@drawable/chart"
android:text="Reports" />
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:icon="@drawable/croissant"
android:text="Hot Potatoes" />
</com.google.android.material.tabs.TabLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
These are the errors I get:
I've tried to add the default material design style to the tab layout but it didn't work
I experienced this too, it seems like it's a known issue with the recommendation to downgrade to 1.17.0. Render Problems with TabLayout and ViewHolder
I did find a workaround, it's not the best solution but I was able to work around the preview breaking by removing the tabs from XML, then adding them in programatically.
tabLayout.addTab(tabLayout.newTab().setText("Tab1"))
tabLayout.addTab(tabLayout.newTab().setText("Tab2"))
It made it so I could still see the rest of my preview, which unblocked me. I also think Android Studio focuses on Compose layout fixes vs XML. So not sure if this will get fixed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With