鸿蒙OS自定义组件实现!

技术宅 2021-06-28 15:59:34 4515

步骤如下:

①在项目上新建 module,选择 libiary 创建鸿蒙组件

②在项目中导入组件

lg\entry\build.gradle 文件中的:
dependencies {
implementation fileTree(dir: 'libs', include: ['.jar', '.har'])
testImplementation 'junit:junit:4.13'
ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100'
下面是导入的组件名 与settings.gradle 名字一样
implementation project(":BottomNavigationF")
}

③在刚才创建的 modul 编写组件类
package com.llt.bottomnavigationf;

import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.agp.components.DirectionalLayout;
import ohos.app.Context;

/*
键盘alt + insert constructor 实现这里面的方法
*/
public class BottomNavigationBar extends DirectionalLayout {

public BottomNavigationBar(Context context) {
    super(context);
}

public BottomNavigationBar(Context context, AttrSet attrSet) {
    super(context, attrSet);
}

public BottomNavigationBar(Context context, AttrSet attrSet, String styleName) {
    super(context, attrSet, styleName);
}

}

④在项目中的 xml 文件引入
<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">

<com.llt.bottomnavigationf.BottomNavigationBar
ohos:height="300vp"
ohos:width="match_parent"
ohos:background_element="#c48c48"

<Text
ohos:height="match_content"
ohos:width="match_content"
ohos:text_color="#fff"
ohos:text_size="28fp"
ohos:text="Text"

123123
</com.llt.bottomnavigationf.BottomNavigationBar>

项目地址:

https://gitee.com/blueskyliu/lg.git

声明:本文内容由易百纳平台入驻作者撰写,文章观点仅代表作者本人,不代表易百纳立场。如有内容侵权或者其他问题,请联系本站进行删除。
红包 93 5 评论 打赏
评论
0个
内容存在敏感词
手气红包
    易百纳技术社区暂无数据
相关专栏
置顶时间设置
结束时间
删除原因
  • 广告/SPAM
  • 恶意灌水
  • 违规内容
  • 文不对题
  • 重复发帖
打赏作者
易百纳技术社区
技术宅
您的支持将鼓励我继续创作!
打赏金额:
¥1易百纳技术社区
¥5易百纳技术社区
¥10易百纳技术社区
¥50易百纳技术社区
¥100易百纳技术社区
支付方式:
微信支付
支付宝支付
易百纳技术社区微信支付
易百纳技术社区
打赏成功!

感谢您的打赏,如若您也想被打赏,可前往 发表专栏 哦~

举报反馈

举报类型

  • 内容涉黄/赌/毒
  • 内容侵权/抄袭
  • 政治相关
  • 涉嫌广告
  • 侮辱谩骂
  • 其他

详细说明

审核成功

发布时间设置
发布时间:
是否关联周任务-专栏模块

审核失败

失败原因
备注
拼手气红包 红包规则
祝福语
恭喜发财,大吉大利!
红包金额
红包最小金额不能低于5元
红包数量
红包数量范围10~50个
余额支付
当前余额:
可前往问答、专栏板块获取收益 去获取
取 消 确 定

小包子的红包

恭喜发财,大吉大利

已领取20/40,共1.6元 红包规则

    易百纳技术社区