Theme/Style is not applied when inflater used with ApplicationContext

前端 未结 4 1915
挽巷
挽巷 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 10:45

    Never use an Application Context to inflate views, because styling doesn't work with this context. Always use an Activity's context when playing with views. The only exception is when you need to create RemoteViews from a Service.

    More info about the different types of Contexts and their capabilities can be found in this excellent article.

提交回复
热议问题