today, I have encountered this problem: I am trying to use a custom TabLayout inside a RecyclerView item. Note that this same component has been used in other parts of the app without issue (never in RecyclerView tho).
The item I am trying to inflate only contains the TabLayout:
<layout 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.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<my.package.CustomTabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent">
<android.support.design.widget.TabItem
android:id="@+id/tab1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/text1" />
<android.support.design.widget.TabItem
android:id="@+id/tab2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/text2" />
</my.package.CustomTabLayout>
</android.support.constraint.ConstraintLayout>
</layout>
the exception:
android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class <unknown>
Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class <unknown>
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.databinding.DataBindingUtil.inflate(DataBindingUtil.java:126)
at android.databinding.DataBindingUtil.inflate(DataBindingUtil.java:95)
at my.package.recycler.MyAdapter.onCreateViewHolder(MyAdapter.kt:25)
at my.package.recycler.MyAdapter.onCreateViewHolder.onCreateViewHolder(MyAdapter.kt:16)
[...]
Caused by: java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library.
at android.support.design.widget.ThemeUtils.checkAppCompatTheme(ThemeUtils.java:33)
at android.support.design.widget.TabLayout.<init>(TabLayout.java:298)
at android.support.design.widget.TabLayout.<init>(TabLayout.java:292)
at my.package.CustomTabLayout.<init>(CustomTabLayout.java:23)
in the adatper I am basically doing this: (can't show the whole code)
DataBindingUtil.inflate(LayoutInflater.from(MyApplication.getContext()), R.layout.tabs_item, parent, false)
there are other inflations in the the adapter, all working correctly.
I can't understand why it's working if used in activity directly but not in RecyclerView
Any idea?