110HCIA
HCIA实验。基于
API19
程序框架服务实验
以多
UIAbility
的微信软件为案例,创建小程序的UIAbility
。模拟微信拉起小程序的效果,即:启动应用内的
UIAbility
;模拟在微信中拉起第三方应用如QQ软件,即:实现应用间跳转。
任务一:启动应用内的 UIAbility
;
创建项目wechat
,并简单设置UI结构。
自行配置项目资源:颜色、图标、app名称、字符串等。
src/main/ets/pages/Index.ets
import { common, Want } from '@kit.AbilityKit'
@Entry
@Component
struct Index {
// 设置微信名称 传递给 被拉起的 UIAbility
wechatName: string = ""
build() {
Column({ space: 30 }) {
Text("模拟微信界面").fontSize(30)
// 启动应用内的 UIAbility;
Column({ space: 10 }) {
TextInput({
placeholder: "请输入你的微信名",
text: $$this.wechatName
})
.width("80%")
.height(40)
Button('单纯的拉起JJ象棋小程序,携带微信名')
.onClick(() => {
// 动态传入微信名,如果用户没输入。设置默认值。
if (this.wechatName === "") {
this.wechatName = "帝心1号"
}
// TODO:拉起小程序
})
}
.ColumnAreaStyle('#51efd5d5')
}
.width('100%')
.height('100%')
.backgroundColor($r('app.color.theme_color'))
}
}
@Extend(Column)
function ColumnAreaStyle(bgc: string) {
.width("90%")
.height(180)
.borderRadius(20)
.backgroundColor(bgc)
.justifyContent(FlexAlign.SpaceEvenly)
}
创建象棋
小程序的 UIAbility
。
-
在
entry
目录上右键新建Ability
。正常取名。例如:JJchessAbility
-
项目自动生成入口类文件:
src/main/ets/jjchessability/JJchessAbility.ets
-
为该Ability配置启动页:
src/main/ets/pages/JJchess.ets
src/main/ets/jjchessability/JJchessAbility.ets
onWindowStageCreate(windowStage: window.WindowStage): void {
windowStage.loadContent("pages/JJchess", (err) => {
if (err.code) {
return;
}
});
}
- 设置
JJchess.ets
页面结构
src/main/ets/pages/JJchess.ets
import { common } from '@kit.AbilityKit'
@Entry
@Component
struct JJchess {
build() {
Column({ space: 30 }) {
Text("模拟JJ象棋小程序").fontSize(30)
Column() {
Button('单纯的停止当前小程序')
.onClick(() => {
// TODO 停止当前 UIAbility
})
}
.ColumnAreaStyle('#51efd5d5')
}
.width('100%')
.height('100%')
.backgroundColor($r('app.color.theme_color'))
}
}
@Extend(Column)
function ColumnAreaStyle(bgc: string) {
.width("90%")
.height(180)
.borderRadius(20)
.backgroundColor(bgc)
.justifyContent(FlexAlign.SpaceEvenly)
}