机器人在运行时动态改变风格 [英] android dynamically change style at runtime

查看:140
本文介绍了机器人在运行时动态改变风格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使我的字体大小可配置的,但我也想利用风格标签在我的布局。是否有可能在运行时更改样式的定义是什么?或者是唯一的选择,手动更改每个的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:

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

现在,当你动态创建新的视图调用构造函数,将允许定义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);

这篇关于机器人在运行时动态改变风格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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