java - 如何从ability_main.xml 初始化 RgbColor?
问题描述
我的库中有一个 RgbColor 类型的自定义属性,我想知道如何使用ability_main.xml 将其初始化为我选择的特定颜色?
解决方案
您可以查看以下示例代码:如果这是具有自定义属性(背景颜色)的 xml 代码
<com.example.application.CustomView
ohos:width="300vp"
ohos:height="100vp"
app:backgroundColor="#FF000000">
在 CustomView.java 中,如果 backgroundColor 值被分配给 RgbColor 对象,那么你可以试试下面的代码
if (attrs.getAttr(BACKGROUND_COLOR).isPresent() && attrs.getAttr(BACKGROUND_COLOR).get() != null) {
mBackgroundColor = new RgbColor(attrs.getAttr(BACKGROUND_COLOR).get().getIntegerValue());
}
推荐阅读
- javascript - 通过一次将属性应用于多个变量来简化代码
- amazon-web-services - 混合内容错误:此请求已被阻止;内容必须通过 HTTPS 提供
- javascript - 如何检测文本的语言/字体;使用正确的字体?或者有人可以建议我使用不同的字体吗?
- list - 将列表转换为正确的数据框
- typescript - 如何对输入数据使用 io-ts 的类型改进?
- java - springboot api服务:“状态”:404,“错误”:“未找到”,
- sendgrid - Sendgrid - 动态模板中的车把错误消息
- python - 使用 Python 从 json 中查找多个条目的最快方法
- java - TypeElement 与 TypeMirror 作为 Java 注释处理器的数据模型
- c# - 为什么我生成的随机数在 .NET Fiddle / dotnetfiddle 中不断变化?