如何在代码中设置colorAccent? [英] How to set colorAccent in code?
问题描述
我想在代码中更改应用程序的主题,所以我用Google搜索它...
不幸的是,我找不到任何方法**
I want to change my application's theme in code , so i google it ...
Unfortunately, i can't find any method to **
.
**我不想像这样在xml中设置此属性...
.
**I don't want to set this attribute in xml like this...
<item name="colorAccent">@color/md_black</item>
或这样...
<item name="android:colorAccent">@color/md_black</item>
请帮助我...
告诉我如何...
对不起,我英语不好,我真的不擅长...
Plz help me...
Just tell me how...
Sorry for my poor english,i'm really not good at it...
推荐答案
您无法通过代码执行此操作.
您可以使用此属性设置默认主题.
You can set a default theme with this attribute.
在要更改颜色的活动中,只需创建一个继承默认主题的主题,但是您为coloAccent设置了另一种颜色
In the activity where you want to change the color, simply create another theme that inherits the default theme, but this new theme you put another color for coloAccent
默认主题:
<item name="colorPrimary">@color/default_color_app</item>
<item name="colorPrimaryDark">@color/default_color_app_dark</item>
<item name="colorAccent">@color/default_color_app_dark</item>
另一项活动:
<style name="BaseTheme.AnotherActivity" parent="BaseTheme">
<item name="colorAccent">@color/another_color</item>
</style>
这篇关于如何在代码中设置colorAccent?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!