鸿蒙OS自定义组件
头像 宋你一朵小红花 2021-06-22 10:00:00    发布
3477 浏览 26 点赞 25 收藏

步骤

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

鸿蒙OS自定义组件-鸿蒙开发者社区


在项目中导入组件

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</Text>
   </com.llt.bottomnavigationf.BottomNavigationBar>
</DirectionalLayout>

项目地址 有问题可以直接提问 https://gitee.com/blueskyliu/lg.git


©本站发布的所有内容,包括但不限于文字、图片、音频、视频、图表、标志、标识、广告、商标、商号、域名、软件、程序等,除特别标明外,均来源于网络或用户投稿,版权归原作者或原出处所有。我们致力于保护原作者版权,若涉及版权问题,请及时联系我们进行处理。
分类
HarmonyOS
头像

宋你一朵小红花

我还没有写个人简介......

881

帖子

0

提问

1679

粉丝

关注
热门推荐
地址:北京市朝阳区北三环东路三元桥曙光西里甲1号第三置业A座1508室 商务内容合作QQ:2291221 电话:13391790444或(010)62178877
版权所有:电脑商情信息服务集团 北京赢邦策略咨询有限责任公司
声明:本媒体部分图片、文章来源于网络,版权归原作者所有,我司致力于保护作者版权,如有侵权,请与我司联系删除
京ICP备:2022009079号-2
京公网安备:11010502051901号
ICP证:京B2-20230255