Set a theme programmatically on Android 5.0 Lollipop

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

android:theme="@style/MyAwesomeTheme"

      

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

+3


source to share


1 answer


android: a theme modifies certain attributes specified in the theme resource. You can create a specific view using any overloaded constructor, eg View(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

. this is basically what the inflator does.

For example, v7.widget.Toolbar

trying to create a thematic context from a resource android:theme

right in the constructor supercall, which is more or less what I mentioned above. Only certain widgets override the app theme using android:theme

.



I am not sure if it is possible to specify the topic directly and not the instance mentioned above, or use a supported custom attribute and associated method.

0


source







All Articles