Я пытаюсь добавить MaterialSearchView , как задокументировано, но родительский макет в моем XML макете - ConstraintLayout, и когда происходит сбой действия, когда я пытаюсь его открыть, журнал говорит, что FrameLayoutParam не может быть приведенным к ConstraintLayoutParam.
Это трассировка стека:
java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to androidx.constraintlayout.widget.ConstraintLayout$LayoutParams
at androidx.constraintlayout.widget.ConstraintLayout.getTargetWidget(ConstraintLayout.java:1144)
at androidx.constraintlayout.widget.ConstraintLayout.setChildrenConstraints(ConstraintLayout.java:1028)
at androidx.constraintlayout.widget.ConstraintLayout.updateHierarchy(ConstraintLayout.java:803)
at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1561)
at android.view.View.measure(View.java:24545)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6828)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
И это мой 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="main.activities.SalesHistoryActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<FrameLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_height="wrap_content">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="@color/colorPrimary"
android:elevation="8dp"
android:theme="@style/CashierToolbarStyle"
app:popupTheme="@style/ThemeOverlay.MaterialComponents.Toolbar.Primary"
app:titleTextColor="@color/white" />
<com.miguelcatalan.materialsearchview.MaterialSearchView
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"/>
</FrameLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/sales_history_list"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar" />
</androidx.constraintlayout.widget.ConstraintLayout>
Инициализация активности:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_orders_history);
butterKnife = ButterKnife.bind(this);
toolbar.setTitle(R.string.orders_history_title);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
searchView.setQuery("ksks", false);
searchView.setOnQueryTextListener(this);
}