华为鸿蒙OS应用开发更换启动首页

您所在的位置:网站首页 华为鸿蒙系统的图标怎么设置 华为鸿蒙OS应用开发更换启动首页

华为鸿蒙OS应用开发更换启动首页

2024-07-16 13:38:46| 来源: 网络整理| 查看: 265

  今天研究了一下华为鸿蒙OS应用开发更换启动首页,首先我们创建个测试项目如下图,我这里设备选择TV,你也可以选择Wearable,模板选择测试Empty Feature Ability(Java)模板

点击Next 跳到如下图

点击Finish按钮后进入项目,定位到下图目录下并创建一个新页面

跳到下图设置Ability名称

点击Finish后工具在创建Ability的同时还帮我们创建了这个Ability对应的AbilitySlice,如下图

接下来将NewsAbilitySlice中的文本内容更改为“测试首页”,代码如下

public class NewsAbilitySlice extends AbilitySlice { private DirectionalLayout myLayout = new DirectionalLayout(this); @Override public void onStart(Intent intent) { super.onStart(intent); LayoutConfig config = new LayoutConfig(LayoutConfig.MATCH_PARENT, LayoutConfig.MATCH_PARENT); myLayout.setLayoutConfig(config); ShapeElement element = new ShapeElement(); element.setRgbColor(new RgbColor(255, 255, 255)); myLayout.setBackground(element); Text text = new Text(this); text.setLayoutConfig(config); text.setText("测试首页"); text.setTextColor(new Color(0xFF000000)); text.setTextSize(50); text.setTextAlignment(TextAlignment.CENTER); myLayout.addComponent(text); super.setUIContent(myLayout); }

现在如果我们运行项目会是默认的首页,如何运行这里就不演示了,我们讲重点,如何更换程序启动首页,首先我们打开main目录下的config.json文件,代码如下

{ "app": { "bundleName": "com.example.myfirsthome", "vendor": "example", "version": { "code": 1, "name": "1.0" }, "apiVersion": { "compatible": 3, "target": 3 } }, "deviceConfig": {}, "module": { "package": "com.example.myfirsthome", "name": ".MyFirstHome", "reqCapabilities": [ "video_support" ], "deviceType": [ "tv" ], "distro": { "deliveryWithInstall": true, "moduleName": "entry", "moduleType": "entry" }, "abilities": [ { "skills": [ { "entities": [ "entity.system.home" ], "actions": [ "action.system.home" ] } ], "orientation": "landscape", "formEnabled": false, "name": "com.example.myfirsthome.MainAbility", "icon": "$media:icon", "description": "$string:mainability_description", "label": "MyFirstHome", "type": "page", "launchType": "standard" }, { "orientation": "landscape", "formEnabled": false, "name": "com.example.myfirsthome.NewsAbility", "icon": "$media:icon", "description": "$string:newsability_description", "label": "entry", "type": "page", "launchType": "standard" } ] } }

重点就是在abilities节点下的第一个对象里面的skills配置,如果我们讲这个skills移到我们刚才建的那个ability对象里,代码如下

{ "app": { "bundleName": "com.example.myfirsthome", "vendor": "example", "version": { "code": 1, "name": "1.0" }, "apiVersion": { "compatible": 3, "target": 3 } }, "deviceConfig": {}, "module": { "package": "com.example.myfirsthome", "name": ".MyFirstHome", "reqCapabilities": [ "video_support" ], "deviceType": [ "tv" ], "distro": { "deliveryWithInstall": true, "moduleName": "entry", "moduleType": "entry" }, "abilities": [ { "orientation": "landscape", "formEnabled": false, "name": "com.example.myfirsthome.MainAbility", "icon": "$media:icon", "description": "$string:mainability_description", "label": "MyFirstHome", "type": "page", "launchType": "standard" }, { "skills": [ { "entities": [ "entity.system.home" ], "actions": [ "action.system.home" ] } ], "orientation": "landscape", "formEnabled": false, "name": "com.example.myfirsthome.NewsAbility", "icon": "$media:icon", "description": "$string:newsability_description", "label": "entry", "type": "page", "launchType": "standard" } ] } }

那么现在如果我们在重新运行项目则启动首页则变成了我们刚才新增的页面,如下图

到这里首页更换就完成了,至于config.json中的配置节点作用可以去华为官方查看链接地址为https://developer.harmonyos.com/cn/docs/documentation/doc-guides/basic-config-file-elements-0000000000034463



【本文地址】

公司简介

联系我们

今日新闻


点击排行

实验室常用的仪器、试剂和
说到实验室常用到的东西,主要就分为仪器、试剂和耗
不用再找了,全球10大实验
01、赛默飞世尔科技(热电)Thermo Fisher Scientif
三代水柜的量产巅峰T-72坦
作者:寞寒最近,西边闹腾挺大,本来小寞以为忙完这
通风柜跟实验室通风系统有
说到通风柜跟实验室通风,不少人都纠结二者到底是不
集消毒杀菌、烘干收纳为一
厨房是家里细菌较多的地方,潮湿的环境、没有完全密
实验室设备之全钢实验台如
全钢实验台是实验室家具中较为重要的家具之一,很多

推荐新闻


图片新闻

实验室药品柜的特性有哪些
实验室药品柜是实验室家具的重要组成部分之一,主要
小学科学实验中有哪些教学
计算机 计算器 一般 打孔器 打气筒 仪器车 显微镜
实验室各种仪器原理动图讲
1.紫外分光光谱UV分析原理:吸收紫外光能量,引起分
高中化学常见仪器及实验装
1、可加热仪器:2、计量仪器:(1)仪器A的名称:量
微生物操作主要设备和器具
今天盘点一下微生物操作主要设备和器具,别嫌我啰嗦
浅谈通风柜使用基本常识
 众所周知,通风柜功能中最主要的就是排气功能。在

专题文章

    CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭