Я использую дизайн материала в качестве темы своего приложения, но из-за этого есть некоторая проблема при просмотре предварительного просмотра макета в Android Studio. Предварительный просмотр не отображается, но когда я запускаю код, я могу просмотреть дизайн на устройстве.
Проблема в основном из-за кнопки материала, которую я использовал. когда я комментирую код кнопки, отображается предварительный просмотр, но когда я раскомментирую код и обновляю макет, предварительный просмотр снова не отображается.
Ниже приведен код того, как я применил тему материала к своему приложению:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
Ниже приведен код, который я использовал в макете:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:layout_marginTop="115dp"
android:layout_centerHorizontal="true"
android:textSize="30dp"
style="@style/text_sui_generis"
android:textColor="@color/colorPrimary"/>
<RelativeLayout
android:id="@+id/rlSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tvTitle"
android:layout_marginTop="80dp"
android:layout_centerHorizontal="true"
android:background="@drawable/border_shadow"
android:padding="5dp">
<ImageView android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/ic_location"
android:id="@+id/locationImage"
android:layout_centerVertical="true"/>
<Spinner
android:id="@+id/locationSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/locationImage"
android:layout_marginStart="5dp"
android:layout_centerVertical="true"/>
</RelativeLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/signin_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sign_in"
style="@style/buttonCustomFont"
android:layout_below="@id/rlSpinner"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
android:elevation="1dp"/>
</RelativeLayout>