1.在AndroidManifest.xml文件中找到 android:theme="@style/Theme.Tablayout"
;
2.ctrl+右键点击@style/Theme.Tablayout,跳转到themes.xml;
3.将"Theme.Material3.DayNight.NoActionBar"替换为Theme.MaterialComponents.Light.Bridge即可显示title;
4.Theme.MaterialComponents.Light.Bridge 显示title;
5.Theme.Material3.DayNight.NoActionBar 不显示title;
AndroidManifest.xml
<?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="31">
<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>
</activity>
</application>
</manifest>
themes.xml
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Base.Theme.Tablayout" parent="Theme.Material3.DayNight.NoActionBar">
<!-- Customize your light theme here. -->
<!-- <item name="colorPrimary">@color/my_light_primary</item> -->
</style>
<style name="Theme.Tablayout" parent="Base.Theme.Tablayout" />
</resources>