如何_really_编程方式更改主要和强调色在Android的棒棒糖? [英] How to _really_ programmatically change primary and accent color in Android Lollipop?

查看:115
本文介绍了如何_really_编程方式更改主要和强调色在Android的棒棒糖?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,<一个href="http://stackoverflow.com/questions/25354558/how-to-change-programmatically-the-primary-color-in-android-l">this问题问了一个非常类似的问题。不过,我的问题有一个微妙的差异。

First of all, this question asks a very similar question. However, my question has a subtle difference.

我想知道的是,是否有可能一个主题的 colorPrimary 属性以编程方式更改为任意颜色?

What I'd like to know is whether it is possible to programmatically change the colorPrimary attribute of a theme to an arbitrary color?

因此​​,例如,我们有:

So for example, we have:

<style name="AppTheme" parent="android:Theme.Material.Light">
    <item name="android:colorPrimary">#ff0000</item>
    <item name="android:colorAccent">#ff0000</item>
</style>

在运行时,用户决定他要用 #ccffff 作为主要颜色。 Ofcourse有没有办法,我可以为所有可能的颜色打造的主题。

At runtime, the user decides he wants to use #ccffff as a primary color. Ofcourse there's no way I can create themes for all possible colors.

我不介意,如果我必须做哈克的东西,就像依靠Android的私有内部,只要它的工作原理使用公共SDK。

I don't mind if I have to do hacky stuff, like relying on Android's private internals, as long as it works using the public SDK.

我的目标是最终有动作条的像所有小工具复选框以使用该原色

My goal is to eventually have the ActionBar and all widgets like a CheckBox to use this primary color.

推荐答案

主题是不可变的,你不能。

Themes are immutable, you can't.

这篇关于如何_really_编程方式更改主要和强调色在Android的棒棒糖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆