动态地从code更改多个TextView的尺寸(无"在磁盘上和QUOT; XML主题)? [英] Dynamically change size of multiple textview from code (without a "on disk" xml theme)?

查看:176
本文介绍了动态地从code更改多个TextView的尺寸(无"在磁盘上和QUOT; XML主题)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有10个的 TextViews 的在我的code和我想对所有的人都改变字体大小。在我的布局我已经使用了的 @style 的定义公共属性,但是我不知道如何把它们全部改由code,一旦布局在屏幕上。

I have 10 TextViews in my code and i would like to change font size on all of them. On my layout i have used a @style to define common properties however i don't know how to change them all from code once layout is on screen.

什么我不想做的就是更新N个对象,但只在一个地方写。我知道,我可以使用的 applyTheme 的,但这假设你有一个XML主题磁盘某处,我希望能够扩展字体任何规模大小所以这个解决方案是不实际的。

What i dont want to do is update N objects but write only in one place. I know that i could use applyTheme but this assumes that you have an XML theme somewhere on disk, i want to be able to scale fonts to any size so this solution is not practical.

任何想法?

推荐答案

请参阅类似的问题:

<一个href=\"http://stackoverflow.com/questions/2016249/how-to-programmatically-setting-style-attribute-in-a-view\">How通过编程设置样式属性在视图中

<一个href=\"http://stackoverflow.com/questions/3241729/android-dynamically-change-style-at-runtime\">android在运行时动态改变风格

机器人:在运行时设置的TextView风格

这听起来像它不可能在运行时改变个人风格元素。您可以应用不同的主题,但随后你需要一个不同的主题要支持所有字体大小。烦人,但有可能。

It sounds like its not possible to change an individual style element at runtime. You could apply a different theme, but then you would need a different theme for every font size you want to support. Annoying, but possible.

否则,您必须要拿出一个办法来减少更新所有textViews的痛苦。你可以存储在您的应用程序类的大小,所以它是由所有的活动的访问,然后在更新的onCreate每个TextView的大小。

Otherwise, you have to come up with a way to reduce the pain of updating all of the textViews. You could store the size in your application class, so it is accessible by all of your activities, and then in onCreate update the size for each TextView.

这篇关于动态地从code更改多个TextView的尺寸(无&QUOT;在磁盘上和QUOT; XML主题)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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