I created a fragment and added a SearchView to it, but the SearchView glows red. The error "Failed to instantiate one or more classes" is returned. And under the error it says "Missing styles".
It is my themes.xml file:
`<resources xmlns:tools="http://schemas.android.com/tools">
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
</style>
<style name="Theme.Notebook" parent="Base.Theme.Notebook" />
<style name="Base.Theme.AppCompat.Light.DarkActionBar"
parent="Base.Theme.Notebook"/>
<style name="ShapeAppearanceOverlay.Material3.SearchView."
parent="ThemeOverlay.Material3.Search"/>
<style name="ThemeOverlay.search" parent="AppTheme">
<item name="android:editTextColor">@color/white</item>
<item name="android:textColorHint">@color/light_grey</item>
</style>
</resources>`
It is my dependencies in build.gradle.kts:
dependencies {
implementation("com.google.android.material:material:1.10.0")
implementation("de.hdodenhof:circleimageview:3.1.0")
implementation("com.intuit.ssp:ssp-android:1.1.0")
implementation("com.intuit.sdp:sdp-android:1.1.0")
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.room:room-runtime:2.6.0")
implementation("com.android.car.ui:car-ui-lib:2.5.1")
annotationProcessor("androidx.room:room-compiler:2.6.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.10.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation
("androidx.test.espresso:espresso-core:3.5.1")
}
It is my 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"
style="@style/Base.Theme.AppCompat.Light.DarkActionBar"
android:layout_height="match_parent"
android:background="@color/dark_violet"
tools:context=".Notebook">
<TextView
android:id="@+id/tv1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/_10ssp"
android:fontFamily="@font/manrope_bold"
android:padding="@dimen/_5sdp"
android:text="@string/notes"
android:textColor="@color/white"
android:textSize="@dimen/_20ssp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.64"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<SearchView
android:id="@+id/search_view"
android:layout_width="393dp"
android:layout_height="58dp"
android:layout_marginStart="9dp"
android:layout_marginTop="62dp"
android:layout_marginEnd="9dp"
android:layout_marginBottom="611dp"
android:background="@drawable/background_notebook"
android:queryHint="@string/search"
android:searchIcon="@drawable/search"
android:theme="@style/ThemeOverlay.search"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
app:searchHintIcon="@color/white" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="387dp"
android:layout_height="203dp"
android:layout_marginStart="12dp"
android:layout_marginTop="120dp"
android:layout_marginEnd="12dp"
android:layout_marginBottom="408dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="@+id/l1"
android:layout_width="418dp"
android:layout_height="75dp"
android:layout_marginTop="662dp"
android:layout_marginEnd="2dp"
android:background="@color/black"
android:orientation="horizontal"
android:padding="@dimen/_10sdp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:layout_width="38dp"
android:layout_height="38dp"
android:src="@drawable/ic_tick"
app:tint="@color/white"
android:contentDescription="@string/empty"/>
<ImageView
android:layout_width="36dp"
android:layout_height="38dp"
android:layout_marginStart="@dimen/_10sdp"
android:layout_marginEnd="@dimen/_10sdp"
android:src="@drawable/ic_image"
app:tint="@color/white"
android:contentDescription="@string/empty"/>
<ImageView
android:layout_width="36dp"
android:layout_height="37dp"
android:src="@drawable/ic_link"
app:tint="@color/white"
android:contentDescription="@string/empty"/>
</LinearLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="54dp"
android:layout_height="52dp"
android:layout_marginStart="336dp"
android:layout_marginTop="627dp"
android:layout_marginEnd="29dp"
android:layout_marginBottom="60dp"
android:background="@color/black"
android:src="@drawable/ic_add"
android:tint="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:contentDescription="@string/todo" />
</androidx.constraintlayout.widget.ConstraintLayout>
I tried to write instead of "" the full path "<androidx.appcompat.widget.SearchView".Then the error disappears, but the appearance of the SearchView also disappears, and instead of the design, just a gray window appears, in which it says "androidx.appcompat.widget.SearchView".
I also tried adding styles to SearchView, but all the styles I tried didn't solve the problem. Project on Kotlin. My minSDK=24, targetSDK=33