Android Studio 2021 2.1.15的渲染问题(样式在模拟器中不会改变)



我正在学习用android studio和Kotlin构建一个应用程序。我刚开始改变textview的样式元素,但模拟器中的视图没有改变。下面是activey_main .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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:layout_marginLeft="@dimen/default_margin"
android:layout_marginTop="@dimen/default_margin"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
style="@style/DefaultTextStyle"/>
</androidx.constraintlayout.widget.ConstraintLayout>

这是"valuesthemes.xml">

的代码
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.NatureCollection" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
<!-- Créer le composant poour le titre par défaut -->
<style name="DefaultTextStyle">
<item name="android:textColor">@color/lightGray</item>
<item name="android:textSize">18sp</item>
<item name="android:fontFamily">@font/Kanit-Regular</item>
</style>
<style name="SubtitleTextStyle" parent="DefaultTextStyle">
<item name="android:textColor">@color/darkGray</item>
</style>
<style name="TitleTextStyle" parent="SubtitleTextStyle">
<item name="android:textSize">24sp</item>
</style>
</resources>

下面是" dimension .xml"的代码:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="default_margin">20dp</dimen>
</resources>

这是"colors.xml":

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="darkGray">#202122</color>
<color name="lightGray">#989ca0</color>
<color name="Green">#77d353</color>
<color name="darkGreen">#5c9447</color>
</resources>

这是"strings.xml"的代码:

<resources>
<string name="app_name">Nature Emoi</string>
<!-- Page d'accueil -->
<string name="home_page_title">A découvrir</string>
<string name="home_page_last_plant_section">Dernières Plantes</string>
<!-- Page de collection -->
<string name="collection_page_title">Ma Collection</string>
<!-- Page d'ajout de plantes -->
<string name="add_plant_page_title">Ajout d'une planet</string>
<string name="add_plant_page_upload_button">Charger Image</string>
<string name="add_plant_page_name_input">@string/item_plant_name</string>
<string name="add_plant_page_description_input">@string/item_plant_description</string>
<string-array name="add_plant_page_grow_spinner_input">
<item>Croissance : Lente</item>
<item>Croissance : Moyenne</item>
<item>Croissance : Rapide</item>
</string-array>
<string-array name="add_plant_page_water_spinner_input">
<item>Consommation : Lente</item>
<item>Consommation : Moyenne</item>
<item>Consommation : Elevée</item>
</string-array>
<string name="add_plant_page_confirm_button">Confirmer</string>
<!-- Fenêtre Pop Up de détails -->
<string name="popup_plant_name">Plant Name</string>
<string name="popup_plant_description_title">Description</string>
<string name="popup_plant_description_subtitle">Une petite description</string>
<string name="popup_plant_grow_title">Croissance</string>
<string name="popup_plant_grow_subtitle">Lente</string>
<string name="popup_plant_water_title">Consommation d'eau</string>
<string name="popup_plant_water_subtitle">Faible</string>

<!-- Plante Customisée -->
<string name="item_plant_name">Nom de la plante</string>
<string name="item_plant_description">Description de la plante</string>
</resources>

模拟器也给我这个错误信息:

下面是模拟器渲染的截图:

提前感谢您的回复

在指定style时应该给style添加parent。下面的代码应该像。

<style name="DefaultTextStyle" parent="android:Theme">