机器人在运行时动态改变风格机器人、风格、动态

2023-09-11 12:16:03 作者:學绘oヤ嗿翫

我想使我的字体大小可配置的,但我也想利用风格标签在我的布局。是否有可能在运行时更改样式的定义是什么?或者是唯一的选择,手动更改每个的TextView等个人风格的元素。?

I'd like to make my font sizes configurable but i'd also like to make use of the style tag in my layouts. Is it possible to change the definition of a style at runtime? or is the only option to manually change the individual style elements on each textview etc.?

推荐答案

不支持创建视图后更改样式..所以你可以做的是:

Changing the style after creating the view is not supported .. so what you can do is:

创建类型值的一个新的Andr​​oid xml文件 添加新的主题 添加元素的主题,他们的价值观和保存文件

现在,当你动态创建新的视图调用构造函数,将允许定义defStyle。然后,你点你刚才所指向R.XML文件名创建的风格ID。你的风格ID

Now, when you are dynamically creating the new view you call the constructor that will allow to define a defStyle. Then, you point to the style ID you have just created by pointing to R."the XML file name"."your style ID"

myTextView.setTextAppearance(getApplicationContext(), R.style.boldText);
 
精彩推荐
图片推荐