有没有一种方法以编程方式更改原色。我想这取决于应用程序的屏幕/状态做,在code。
Is there a way to change programmatically the primary colors. I would like to do it in code depending the screen/state of the app.
目前我只能设置颜色的主题(静态):
Currently I can only set the colors in the theme (static) :
<item name="android:colorPrimary">@color/primary_color</item> <item name="android:colorPrimaryDark">@color/dark_color</item> <item name="android:colorBackground">@android:color/white</item> <item name="android:colorAccent">@color/primary_color</item> <item name="android:colorControlHighlight">@color/primary_color</item>
感谢
推荐答案可以,当然,实现认为有设置颜色的方法定制子类。
You can, of course, implement custom subclasses of View that have methods for setting colors.
您也可以定义多个主题与你不同的配色方案。
You can also define multiple themes with you various color schemes.
Views查找主题信息,从上下文在创建时。因此,要改变从一个主题,你将不得不重新创建视图层次结构与使用权为主题的环境中应用的样式。
Views look up theme information from the context when they are created. So to change the styles applied from a theme you will have to recreate your view hierarchy with a context that uses the right theme.
要做到这一点的方法之一,是创建一个新的ContextThemeWrapper然后得到使用该主题包装一个LayoutInflator,删除旧版本的布局,并重新膨胀的布局。
One way to do that, is to create a new ContextThemeWrapper and then get a LayoutInflator that uses that theme wrapper, remove the old version of your layout and re-inflate your layout.
大致为:
ContextThemeWrapper themeWrapper = new ContextThemeWrapper(this, R.style.AppThemeWithColorScheme2); LayoutInflater layoutInflater = LayoutInflater.from(themeWrapper); viewContainer.removeAllViews(); layoutInflater.inflate(R.layout.my_layout, viewContainer, true );如果您使用的是操作栏,这可能是比较麻烦一些,因为操作栏创建once每个活动。
If you are using Action Bar, that may be a bit more tricky, because the Action Bar is created once per activity.
更多推荐
如何改变编程原色Android中大号
发布评论