Material-components-android: Support using components in service

Created on 21 Feb 2020  路  5Comments  路  Source: material-components/material-components-android

I want to use components in service when using WindowManager.addView but this is impossible now. Because components only use with Material theme.

Thanks!

feature request

Most helpful comment

Thank you! It worked fine!

val contextThemeWrapper = ContextThemeWrapper(this, R.style.Theme_MaterialComponents)
val inflater = LayoutInflater.from(contextThemeWrapper)

All 5 comments

Can you wrap the context you use to create the views in a ContextThemeWrapper with one of our
themes?

new ContextThemeWrapper(context, R.style.Theme_MaterialComponents)

Thank you! It worked fine!

val contextThemeWrapper = ContextThemeWrapper(this, R.style.Theme_MaterialComponents)
val inflater = LayoutInflater.from(contextThemeWrapper)

No problem! We do always want to use Themes. Since our components read attributes from there.

I found the useful article about usage ContextThemeWrapper

https://ataulm.github.io/2019/11/20/using-context-theme-wrapper.html

I'm trying to do this for an soft input (the service is an InputMethodService). The ContextThemeWrapper seems to be working, but only on some devices the background scrim is added. Do you have any clue why that is or what I could check to figure out what I'm doing wrong?

Was this page helpful?
0 / 5 - 0 ratings