从代码(没有“on disk”xml主题))动态更改多个textview的大小? [英] Dynamically change size of multiple textview from code (without a "on disk" xml theme)?

查看:175
本文介绍了从代码(没有“on disk”xml主题))动态更改多个textview的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码中有10个TextViews ,我想改变所有的字体大小。在我的布局上,我使用了一个 @style 来定义公共属性,但是我不知道如何在屏幕上布局布局之后,更改代码。

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.

任何想法?

推荐答案

查看类似的问题:

如何以编程方式设置样式属性一个视图

android在运行时动态更改样式

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.

否则,您必须提出一种方法来减少更新所有textView的痛苦。您可以在应用程序类中存储大小,因此可以通过所有活动访问,然后在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.

这篇关于从代码(没有“on disk”xml主题))动态更改多个textview的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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