如何覆盖具有自己活动的库的样式 [英] How to override styles of a library which has its own Activity
问题描述
我有一个图书馆,图书馆有自己的带有colorPrimary和colorPrimaryDark属性的活动.在使用该库的应用程序中,这些颜色属性具有不同的值.
I have a library which has its own Activities with colorPrimary and colorPrimaryDark attributes. In the application which is using this library, there are different values for these color attributes.
有没有一种方法可以使库使用调用者应用程序提供的样式?
Is there a way to make the library use the style provided by the caller application?
最后,如果应用程序具有绿色工具栏,则库中的活动将具有绿色工具栏,而不是库主题中定义的工具栏.
So that in the end, if the app has a green toolbar, the activities in the library would have a green toolbar, not the one defined in library theme.
这是图书馆的主题:
<style name="LibraryTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/red</item>
<item name="colorPrimaryDark">@color/dark_red</item>
</style>
这是示例应用程序的主题:
And this is the sample app's main theme:
<style name="SampleAppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/green</item>
<item name="colorPrimaryDark">@color/dark_green</item>
<item name="colorAccent">@color/accent_color</item>
</style>
推荐答案
如果"colorPrimary"将使用相同的值-@color/primaryColor
,则示例应用程序中的库primaryColor
的值将被primaryColor
覆盖.
If "colorPrimary" will use the same value - @color/primaryColor
, then value of library primaryColor
will be overridden by primaryColor
in sample app.
如果您在库和应用程序中对"colorPrimary"使用不同的值,例如-@color/libPrimaryColor
和@color/appPrimaryColor
,则颜色将不同
If you will use different values for "colorPrimary" in library and app, for example - @color/libPrimaryColor
and @color/appPrimaryColor
then colors will be different
这篇关于如何覆盖具有自己活动的库的样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!