Skip to content
Advertisement

AppCompat widget that can only be used with a Theme.AppCompat theme (or descendant)

iOS developer here thrown to the wolves of an Android project. I am getting a few error codes that all say something similar to ThemeUtils: View class androidx.appcompat.widget.AppCompatTextView is an AppCompat widget that can only be used with a Theme.AppCompat theme (or descendant). as soon as the following code snippet runs:

JavaScript

My inflater is instantiated as follows:

JavaScript

SqueaksApplication.getApplicationInstance() just returns an instance of public class SqueaksApplication extends Application

Almost every answer I have found to this question points to the project’s manifest as the issue and needing to provide a theme for the project. My project’s manifest looks like the following:

JavaScript

As you can see my manifest already includes the line android:theme="@style/AppTheme"

My project uses the layout inflator in many different places, but this is the only one I have come across that is throwing errors. Would appreciate any insight, or solutions you may have, thanks!

Edit: As requested this is my styles.xml:

JavaScript

Advertisement

Answer

Your issue is the context used: val inflater: LayoutInflater = LayoutInflater.from(SqueaksApplication.getApplicationInstance()).

The ApplicationContext doesn’t have your app theme.
You need to pass the Activity, not an Application Context.

Advertisement