在视图中设置一个主题编程在Android 5.0棒棒糖 [英] Set a theme on a View programmatically on Android 5.0 Lollipop
问题描述
是Android 5.0棒棒糖加入到设置不同的看法主题(不仅仅是活动)的能力。
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?
推荐答案
机器人:主题改变了主题资源指定的特定属性。你可以使用任何重载的构造函数,如查看具体的实例化视图(上下文的背景下,ATTRS的AttributeSet,诠释defStyleAttr,诠释defStyleRes)
。这基本上是做什么吹气。
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.
例如 v7.widget.Toolbar
试图创建主题的背景下出来的资源安卓主题
就在构造函数的超级调用,这是多了还是少了什么我上面提到的。主题:只有某些部件使用的Android应用程序重写主题。
For example v7.widget.Toolbar
tries to create themed context out of resource android:theme
right 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.
这篇关于在视图中设置一个主题编程在Android 5.0棒棒糖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!