我的库中有一个 RgbColor 类型的自定义属性,我想知道如何使用ability_main.xml 将其初始化为我选择的特定颜色?
问问题
22 次
1 回答
0
您可以查看以下示例代码:如果这是具有自定义属性(背景颜色)的 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());
}
于 2021-08-17T14:04:25.333 回答