Set a theme on a View programmatically on Android 5.0 Lollipop

跟風遠走 提交于 2019-12-06 08:20:46

问题


Android 5.0 Lollipop added the ability to set a theme for different views (not just the Activity).

android:theme="@style/MyAwesomeTheme"

Is there a way to set the theme on a view dynamically?


回答1:


android:theme changes specific attributes specified in the theme resource. You could instantiate specific view using any overloaded constructor, like View(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes). which basically is what inflater does.

For example v7.widget.Toolbar tries to create themed context out of resource android:themeright in the super call of the constructor, which is more or less what I mentioned above. Only certain widgets override application theme using android:theme.

I'm not sure if is possible to directly specify theme, rather than instantiation mentioned above, or using supported individual attribute and its related method.



来源:https://stackoverflow.com/questions/27084343/set-a-theme-on-a-view-programmatically-on-android-5-0-lollipop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!