You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

向TabLayout添加TabItem时Android Studio预览崩溃求助

Android Studio布局预览崩溃问题(添加TabItem时失效)

多台电脑上的Android Studio均出现布局预览崩溃问题,最近的触发场景是向TabLayout中添加TabItem时,预览功能直接失效。已尝试以下所有方案,但问题仍未解决:

  • 清理并重建项目
  • 清除Android Studio缓存并重启
  • 重启笔记本电脑
  • 检查布局文件,确认无语法错误,仅存在提取字符串的警告
  • 确认Material Components依赖版本为最新的1.8.0
  • 为TabLayout配置默认Material Design样式

布局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=".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>

报错截图

  • 错误总览
  • 第一个错误详情
  • 第二个错误详情
  • 第三个错误详情

内容的提问来源于stack exchange,提问作者Charbel983

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 13:22:16