2

I have a custom RelativeLayout and want to use the android support design library inside it (so I can use the CoordinatorLayout). I've tried adding

android:theme="@style/Theme.AppCompat.Light"

but am still getting this error:

Caused by: java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library.

Does this mean that I cannot use it on a custom view and only inside an Activity? Because I cannot use an activity here. I'm adding this view to the WindowManager. Any help is highly appreciated. Thanks!

Alex Age
  • 41
  • 1

2 Answers2

2

Because you are adding the view with WindowManager and a Theme.AppCompat compatible theme is needed, you just need to set your theme before calling your LayoutInflater. For example: setTheme(R.style.AppTheme); It should work :)

Sloosh
  • 1,681
  • 1
  • 10
  • 14
1

In my case, I needed to add a android.support.design.widget.TabLayout to my custom keyboard. I solved the problem with:

override fun onCreate() {
    setTheme(R.style.AppTheme)

    super.onCreate()
}
Binkan Salaryman
  • 3,008
  • 1
  • 17
  • 29
Sami Issa
  • 1,695
  • 1
  • 18
  • 29
  • 2
    Please don't add _"thanks"_ as answers. They don't actually provide an answer to the question, and can be perceived as noise by its future visitors. Instead, [upvote answers](http://stackoverflow.com/help/privileges/vote-up) you like. This way future visitors of the question will see a higher vote count on that answer, and the answerer will also be rewarded with reputation points. See [Why is voting important](http://stackoverflow.com/help/why-vote). – LW001 May 12 '18 at 13:30