Theme/Style is not applied when inflater used with ApplicationContext

前端 未结 4 1914
挽巷
挽巷 2020-11-28 10:40

I have theme that specifies textColor for TextView as red.

I am using LayoutInflater to instantiate TextView. The problem is that styles are not applied to TextView

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 11:02

    You probably use a context that isn't one that has a theme.

    To solve it, use something as such:

    val inflater= LayoutInflater.from(context).cloneInContext(ContextThemeWrapper(context, R.style.some_activity_theme))
    

    You can read more about this here

提交回复
热议问题