如何改变编程原色Android中大号

编程入门 行业动态 更新时间:2024-10-11 15:14:38
本文介绍了如何改变编程原色Android中大号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有没有一种方法以编程方式更改原色。我想这取决于应用程序的屏幕/状态做,在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中大号

本文发布于:2023-11-29 13:58:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646585.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:原色   大号   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!