我正在制作一个多主题应用程序,我想为依赖于当前主题的所有图像设置色调属性。
像这样
<style name="AppTheme.Default" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#EA7819</item>
<item name="colorPrimaryDark">#CF6415</item>
<item name="colorAccent">#3498DB</item>
<item name="toolbarStyle">@style/Theme.AppCompat</item>
</style>
我可以在主题中设置工具栏样式,我可以用 imageView 做类似的事情吗?
最佳答案
您必须在每个 ImageView
中设置色调颜色,如下所示:
// define your attr
<resources>
<attr name="image_tint_color" format="reference"/>
</resources>
// create multiple themes: YourTheme1, YourTHeme2...
<style name="YourTheme1" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="image_tint_color">yourColor</item>
</style>
// After setting theme in activity:
setTheme(R.style.yourTheme1)
// Then you can use the color everywhere:
android:tint="?attr/image_tint_color"
你可以看看Detail Guide Here
关于android - 如何在主题中设置图像样式。安卓?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54466111/