【问题标题】:How to initialise RgbColor from ability_main.xml?如何从ability_main.xml 初始化 RgbColor?
【发布时间】:2021-07-30 10:40:19
【问题描述】:

我的库中有一个 RgbColor 类型的自定义属性,我想知道如何使用ability_main.xml 将其初始化为我选择的特定颜色?

【问题讨论】:

  • hi@Shrey Shrivastava,您能否发布一些您图书馆的代码,以便我们找到您的问题?

标签: java android huawei-mobile-services huawei-developers harmonyos


【解决方案1】:

您可以查看以下示例代码: 如果这是带有自定义属性(背景颜色)的 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());
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-17
    • 1970-01-01
    • 2019-08-08
    • 2017-03-29
    相关资源
    最近更新 更多