diff --git a/ArkUIKit/ChooseComponent/README_zh.md b/ArkUIKit/ChooseComponent/README_zh.md
index e1a335f5c5cadf23acc0c926cf8d572fac691729..07f29630f3545baf30ef571a8e81f36ef3edf5b6 100644
--- a/ArkUIKit/ChooseComponent/README_zh.md
+++ b/ArkUIKit/ChooseComponent/README_zh.md
@@ -29,9 +29,12 @@ entry/src/main/ets/
|---entryability
|---pages
| |---button
+| | |---ButtionCase1.ets // 按钮创建示例代码
+| | |---ButtionCase2.ets // 按钮创建示例代码
| | |---CreateButton.ets // 按钮创建示例代码
| | |---ButtonCustomStyle.ets // 按钮自定义示例代码
| | |---FloatingButton.ets // 按钮悬浮场景示例代码
+| | |---HoverButtonExample.ets // 按钮悬浮场景示例代码
| | |---Index.ets // 第二层级目录
| | |---SetButtonType.ets // 按钮类型设置示例代码
| | |---SubmitForm.ets // 按钮注册场景示例代码
@@ -50,6 +53,8 @@ entry/src/ohosTest/
|---ets
| |---index.test.ets // 示例代码测试代码
```
+## 具体实现
+Button是按钮组件,通常用于响应用户的点击操作,其类型包括胶囊按钮、圆形按钮、普通按钮、圆角矩形按钮。Button作为容器使用时可以通过添加子组件实现包含文字、图片等元素的按钮
### 相关权限
diff --git a/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/ButtonCase1.ets b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/ButtonCase1.ets
new file mode 100644
index 0000000000000000000000000000000000000000..565f6bd333648a7c7a25089127ddb5fc99c9f9df
--- /dev/null
+++ b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/ButtonCase1.ets
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2025 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { hilog } from '@kit.PerformanceAnalysisKit';
+// [Start button_case_1]
+const DOMAIN = 0x0000;
+// xxx.ets
+@Entry
+@Component
+export struct ButtonCase1 {
+ pathStack: NavPathStack = new NavPathStack();
+
+ @Builder
+ PageMap(name: string) {
+ if (name === 'first_page') {
+ pageOneTmp()
+ } else if (name === 'second_page') {
+ pageTwoTmp()
+ } else if (name === 'third_page') {
+ pageThreeTmp()
+ }
+ }
+
+ build() {
+ // [StartExclude button_case_1]
+ NavDestination() {
+ // [EndExclude button_case_1]
+
+ Navigation(this.pathStack) {
+ List({ space: 4 }) {
+ ListItem() {
+ Button('First').onClick(() => {
+ this.pathStack.pushPath({ name: 'first_page' });
+ })
+ .width('100%')
+ }
+
+ ListItem() {
+ Button('Second').onClick(() => {
+ this.pathStack.pushPath({ name: 'second_page' });
+ })
+ .width('100%')
+ }
+
+ ListItem() {
+ Button('Third').onClick(() => {
+ this.pathStack.pushPath({ name: 'third_page' });
+ })
+ .width('100%')
+ }
+ }
+ .listDirection(Axis.Vertical)
+ .backgroundColor(0xDCDCDC).padding(20)
+ }
+ .mode(NavigationMode.Stack)
+ .navDestination(this.PageMap)
+ // [StartExclude button_case_1]
+ }
+ // [EndExclude button_case_1]
+ }
+}
+
+// pageOne
+@Component
+export struct pageOneTmp {
+ pathStack: NavPathStack = new NavPathStack();
+
+ build() {
+ NavDestination() {
+ Column() {
+ Text('first_page')
+ }.width('100%').height('100%')
+ }.title('pageOne')
+ .onBackPressed(() => {
+ const popDestinationInfo = this.pathStack.pop(); // 弹出路由栈栈顶元素
+ hilog.info(DOMAIN, 'testTag', 'pop' + '返回值' + JSON.stringify(popDestinationInfo));
+ return true
+ })
+ .onReady((context: NavDestinationContext) => {
+ this.pathStack = context.pathStack;
+ })
+ }
+}
+
+// pageTwo
+@Component
+export struct pageTwoTmp {
+ pathStack: NavPathStack = new NavPathStack();
+
+ build() {
+ NavDestination() {
+ Column() {
+ Text('second_page')
+ }.width('100%').height('100%')
+ }.title('pageTwo')
+ .onBackPressed(() => {
+ const popDestinationInfo = this.pathStack.pop(); // 弹出路由栈栈顶元素
+ hilog.info(DOMAIN, 'testTag', 'pop' + '返回值' + JSON.stringify(popDestinationInfo));
+ return true
+ })
+ .onReady((context: NavDestinationContext) => {
+ this.pathStack = context.pathStack;
+ })
+ }
+}
+
+// pageThree
+@Component
+export struct pageThreeTmp {
+ pathStack: NavPathStack = new NavPathStack();
+
+ build() {
+ NavDestination() {
+ Column() {
+ Text('third_page')
+ }.width('100%').height('100%')
+ }.title('pageThree')
+ .onBackPressed(() => {
+ const popDestinationInfo = this.pathStack.pop(); // 弹出路由栈栈顶元素
+ hilog.info(DOMAIN, 'testTag', 'pop' + '返回值' + JSON.stringify(popDestinationInfo));
+ return true
+ })
+ .onReady((context: NavDestinationContext) => {
+ this.pathStack = context.pathStack;
+ })
+ }
+}
+// [End button_case_1]
\ No newline at end of file
diff --git a/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/ButtonCase2.ets b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/ButtonCase2.ets
new file mode 100644
index 0000000000000000000000000000000000000000..cedb508b6cf54e0d1b50a5a498fdd3c8027a8bbd
--- /dev/null
+++ b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/ButtonCase2.ets
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2025 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { hilog } from '@kit.PerformanceAnalysisKit';
+// [Start button_case_2]
+// xxx.ets
+const DOMAIN = 0x0000;
+@Entry
+@Component
+export struct ButtonCase2 {
+ build() {
+ // [StartExclude button_case_2]
+ NavDestination() {
+ // [EndExclude button_case_2]
+ Column() {
+ TextInput({ placeholder: 'input your username' }).margin({ top: 20 })
+ TextInput({ placeholder: 'input your password' }).type(InputType.Password).margin({ top: 20 })
+ Button('Register').width(300).margin({ top: 20 })
+ .onClick(() => {
+ // 需要执行的操作
+ })
+ // [StartExclude button_case_2]
+
+ // [Start button_case2_add_event]
+ Button('Ok', { type: ButtonType.Normal, stateEffect: true })
+ .onClick(()=>{
+ hilog.info(DOMAIN, 'testTag', 'Button onClick')
+ }).margin(10)
+ // [Start button_case2_add_event]
+ // [EndExclude button_case_2]
+ }.padding(20)
+ // [StartExclude button_case_2]
+ }
+ // [EndExclude button_case_2]
+ }
+}
+// [End button_case_2]
\ No newline at end of file
diff --git a/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/ButtonCustomStyle.ets b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/ButtonCustomStyle.ets
index dfbc79820732da7a70944289750bfd113e8b5222..da855939af7092be52ba2bdb3ac6572bf5dbd14a 100644
--- a/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/ButtonCustomStyle.ets
+++ b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/ButtonCustomStyle.ets
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024 Huawei Device Co., Ltd.
+ * Copyright (c) 2024-2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -36,6 +36,12 @@ export struct ButtonCustomStyle {
.id('circle_border')
.borderRadius(10)
// [End custom_button_border_radius]
+
+ // [Start custom_button_border_radius2]
+ Button('circle border', { type: ButtonType.Normal })
+ .borderRadius(20)
+ .height(40)
+ // [End custom_button_border_radius2]
}
ComponentCard({
@@ -48,6 +54,14 @@ export struct ButtonCustomStyle {
.fontColor(Color.Pink)
.fontWeight(800)
// [End custom_font_style]
+
+
+ // [Start custom_font_style2]
+ Button('font style', { type: ButtonType.Normal })
+ .fontSize(20)
+ .fontColor(Color.Pink)
+ .fontWeight(800)
+ // [End custom_font_style2]
}
ComponentCard({
@@ -58,6 +72,21 @@ export struct ButtonCustomStyle {
Button('Button').id('background_color')
.backgroundColor(Color.Red)
// [End custom_background_color]
+ // [Start custom_background_color2]
+ Button('background color').backgroundColor(0xF55A42)
+ // [Start custom_background_color2]
+ }
+
+ ComponentCard({
+ title: $r('app.string.SetButtonType_titleFive'),
+ description: $r('app.string.SetButtonType_descriptionFive')
+ }) {
+ //图片需要更换,left使用方式做了修改
+ // [Start custom_create_function_button]
+ Button({ type: ButtonType.Circle, stateEffect: true }) {
+ Image($r('sys.media.ohos_ic_public_cancel')).width(30).height(30)
+ }.width(55).height(55).margin({ 'left': 20 }).backgroundColor(0xF55A42)
+ // [End custom_create_function_button]
}
}
.width('100%')
diff --git a/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/CreateButton.ets b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/CreateButton.ets
index d903c8599d0ab0c0d8e93fa44da34b2411ddc72d..c35769b9bebf59c5a92a8938f5f86ebb472c1734 100644
--- a/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/CreateButton.ets
+++ b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/CreateButton.ets
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024 Huawei Device Co., Ltd.
+ * Copyright (c) 2024-2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -32,6 +32,14 @@ export struct CreateButton {
Button('Button', { type: ButtonType.Capsule, stateEffect: true })
.id('button')
// [End create_button_by_label]
+
+ // [Start create_button_by_label2]
+ Button('Ok', { type: ButtonType.Normal, stateEffect: true })
+ .borderRadius(8)
+ .backgroundColor(0x317aff)
+ .width(90)
+ .height(40)
+ // [End create_button_by_label2]
}
ComponentCard({
@@ -46,6 +54,16 @@ export struct CreateButton {
}.alignItems(VerticalAlign.Center).justifyContent(FlexAlign.Center).width(90).height(40)
}.id('button_back')
// [End create_button_by_button_options]
+
+ // [Start create_button_by_button_options2]
+ //注意图片不一致
+ Button({ type: ButtonType.Normal, stateEffect: true }) {
+ Row() {
+ Image($r('sys.media.ohos_ic_back')).width(20).height(40).margin({ left: 12 })
+ Text('loading').fontSize(12).fontColor(0xffffff).margin({ left: 5, right: 12 })
+ }.alignItems(VerticalAlign.Center)
+ }.borderRadius(8).backgroundColor(0x317aff).width(90).height(40)
+ // [Start create_button_by_button_options2]
}
}
.width('100%')
diff --git a/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/HoverButtonExample.ets b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/HoverButtonExample.ets
new file mode 100644
index 0000000000000000000000000000000000000000..927e3ce4e171ada83773701b1e1b8f10ff54e288
--- /dev/null
+++ b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/HoverButtonExample.ets
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2025 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+// xxx.ets
+@Entry
+@Component
+export struct HoverButtonExample {
+ private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
+ build() {
+ // [StartExclude hover_button_example]
+ NavDestination() {
+ // [EndExclude hover_button_example]
+ Stack() {
+ List({ space: 20, initialIndex: 0 }) {
+ ForEach(this.arr, (item: number) => {
+ ListItem() {
+ Text('' + item)
+ .width('100%')
+ .height(100)
+ .fontSize(16)
+ .textAlign(TextAlign.Center)
+ .borderRadius(10)
+ .backgroundColor(0xFFFFFF)
+ }
+ }, (item: number) => item.toString())
+ }.width('90%')
+
+ Button() {
+ //注意图片需要替换
+ Image($r('sys.media.ohos_ic_public_add'))
+ .width(50)
+ .height(50)
+ }
+ .width(60)
+ .height(60)
+ .position({ x: '80%', y: 600 })
+ .shadow({ radius: 10 })
+ .onClick(() => {
+ // 需要执行的操作
+ })
+ }
+ .width('100%')
+ .height('100%')
+ .backgroundColor(0xDCDCDC)
+ .padding({ top: 5 })
+ // [StartExclude hover_button_example]
+ }
+ // [EndExclude hover_button_example]
+ }
+}
+// [End button_case_1]
\ No newline at end of file
diff --git a/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/Index.ets b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/Index.ets
index f37f6f3bd71096b1f6fd86e9612037192180f1cb..a51d7b9318a1831d2713e19059b254b21b8523da 100644
--- a/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/Index.ets
+++ b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/Index.ets
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024 Huawei Device Co., Ltd.
+ * Copyright (c) 2024-2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -21,6 +21,9 @@ import { Route } from '../../common/Route';
import { SetButtonType } from './SetButtonType';
import { SubmitForm } from './SubmitForm';
import resource from '../../common/resource'
+import { ButtonCase1 } from './ButtonCase1';
+import { ButtonCase2 } from './ButtonCase2';
+import { HoverButtonExample } from './HoverButtonExample';
export const BUTTON_ROUTE_PREFIX: string = 'button';
@@ -50,7 +53,21 @@ const routes: Route[] = [
title: resource.resourceToString($r('app.string.FloatingButton_title')),
description: $r('app.string.FloatingButton_description')
},
-]
+ {
+ name: `${BUTTON_ROUTE_PREFIX}/ButtonCase1`,
+ title: resource.resourceToString($r('app.string.ButtonCase1_title')),
+ description: $r('app.string.ButtonCase1_desc')
+ },
+ {
+ name: `${BUTTON_ROUTE_PREFIX}/ButtonCase2`,
+ title: resource.resourceToString($r('app.string.ButtonCase2_title')),
+ description: $r('app.string.ButtonCase2_desc')
+ },
+ {
+ name: `${BUTTON_ROUTE_PREFIX}/HoverButtonExample`,
+ title: resource.resourceToString($r('app.string.HoverButtonExample_title')),
+ description: $r('app.string.HoverButtonExample_desc')
+ }]
@Builder
export function buttonDestination(name: string) {
@@ -66,6 +83,12 @@ export function buttonDestination(name: string) {
SubmitForm();
} else if (name === routes[4].name) {
FloatingButton();
+ } else if (name === routes[5].name) {
+ ButtonCase1();
+ } else if (name === routes[6].name) {
+ ButtonCase2();
+ } else if (name === routes[7].name) {
+ HoverButtonExample();
}
}
diff --git a/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/SetButtonType.ets b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/SetButtonType.ets
index 489944cc97e22d3f1d81c1e1ce544bc4c10e186c..7d397b7d7d9600767ecf3853e197d6d7a0beac17 100644
--- a/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/SetButtonType.ets
+++ b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/SetButtonType.ets
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024 Huawei Device Co., Ltd.
+ * Copyright (c) 2024-2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -35,6 +35,13 @@ export struct SetButtonType {
Button('Button', { type: ButtonType.Capsule })
.id('Capsule')
// [End create_capsule_button]
+
+ // [Start create_capsule_button2]
+ Button('Disable', { type: ButtonType.Capsule, stateEffect: false })
+ .backgroundColor(0x317aff)
+ .width(90)
+ .height(40)
+ // [End create_capsule_button2]
}
ComponentCard({
@@ -46,6 +53,13 @@ export struct SetButtonType {
.id('Circle')
.width(80)
// [End create_circle_button]
+
+ // [Start create_circle_button2]
+ Button('Circle', { type: ButtonType.Circle, stateEffect: false })
+ .backgroundColor(0x317aff)
+ .width(90)
+ .height(90)
+ // [End create_circle_button2]
}
ComponentCard({
@@ -56,6 +70,14 @@ export struct SetButtonType {
Button('Button', { type: ButtonType.Normal })
.id('Normal')
// [End create_normal_button]
+
+ // [Start create_normal_button2]
+ Button('Ok', { type: ButtonType.Normal, stateEffect: true })
+ .borderRadius(8)
+ .backgroundColor(0x317aff)
+ .width(90)
+ .height(40)
+ // [End create_normal_button2]
}
ComponentCard({
@@ -64,6 +86,12 @@ export struct SetButtonType {
}) {
Button('Button', { type: ButtonType.ROUNDED_RECTANGLE })
.id('Round')
+
+ // [Start create_rounded_rectangle_button]
+ Button('Disable', { type: ButtonType.ROUNDED_RECTANGLE, stateEffect: true })
+ .backgroundColor(0x317aff)
+ .width(90)
+ // [End create_rounded_rectangle_button]
}
}
.width('100%')
diff --git a/ArkUIKit/ChooseComponent/entry/src/main/resources/base/element/string.json b/ArkUIKit/ChooseComponent/entry/src/main/resources/base/element/string.json
index 7de4f7438880b75133e55ce1f1e5bf6ce26bfe0a..682837839545949e75eec483fc82e8df5bbfb32c 100644
--- a/ArkUIKit/ChooseComponent/entry/src/main/resources/base/element/string.json
+++ b/ArkUIKit/ChooseComponent/entry/src/main/resources/base/element/string.json
@@ -112,6 +112,10 @@
"name": "SetButtonType_titleFour",
"value": "圆角矩形按钮"
},
+ {
+ "name": "SetButtonType_titleFive",
+ "value": "创建功能型按钮"
+ },
{
"name": "SetButtonType_description",
"value": "Button 组件的类型的设置,共有四种类型:胶囊按钮、圆形按钮、普通按钮、圆角矩形按钮。"
@@ -132,6 +136,10 @@
"name": "SetButtonType_descriptionFour",
"value": "通过type属性为ButtonType.ROUNDED_RECTANGLE,将按钮类型设置为圆角矩形按钮。"
},
+ {
+ "name": "SetButtonType_descriptionFive",
+ "value": "创建删除操作的按钮。"
+ },
{
"name": "ButtonCustomStyle_test",
"value": "按钮样式"
@@ -207,6 +215,30 @@
"name": "toggle",
"value": "切换按钮/Toggle"
},
+ {
+ "name": "ButtonCase1_title",
+ "value": "启动操作"
+ },
+ {
+ "name": "ButtonCase1_desc",
+ "value": "可以用按钮启动任何用户界面元素,按钮会根据用户的操作触发相应的事件。"
+ },
+ {
+ "name": "ButtonCase2_title",
+ "value": "提交表单"
+ },
+ {
+ "name": "ButtonCase2_desc",
+ "value": "在用户登录/注册页面,使用按钮进行登录或注册操作"
+ },
+ {
+ "name": "HoverButtonExample_title",
+ "value": "悬浮按钮"
+ },
+ {
+ "name": "HoverButtonExample_desc",
+ "value": "在可以滑动的界面,滑动时按钮始终保持悬浮状态"
+ },
{
"name": "RadioSample2_title",
"value": "单选框示例2"
diff --git a/ArkUIKit/ChooseComponent/entry/src/ohosTest/ets/test/Index.test.ets b/ArkUIKit/ChooseComponent/entry/src/ohosTest/ets/test/Index.test.ets
index 40ebdd1f0002615313b7731118edeec704329eb4..05d6f070eebf1d9d0d068a09cab8e4514e622cb7 100644
--- a/ArkUIKit/ChooseComponent/entry/src/ohosTest/ets/test/Index.test.ets
+++ b/ArkUIKit/ChooseComponent/entry/src/ohosTest/ets/test/Index.test.ets
@@ -70,6 +70,12 @@ export default function IndexTest() {
expect(button_back === null).assertFalse();
await button_normal.click();
await button_back.click();
+
+ let buttons = await driver.findComponents(ON.type('Button'))
+ let ok_normal = buttons[1]
+ let loading_button = buttons[3]
+ await ok_normal.click();
+ await loading_button.click();
await driver.pressBack();
await driver.pressBack();
done();
@@ -98,6 +104,12 @@ export default function IndexTest() {
await button_Circle.click();
await button_Normal.click();
await button_Round.click();
+
+ let buttons = await driver.findComponents(ON.type('Button'))
+ await buttons[1].click();
+ await buttons[3].click();
+ await buttons[5].click();
+ await buttons[7].click();
await driver.pressBack();
await driver.pressBack();
done();
@@ -123,6 +135,13 @@ export default function IndexTest() {
await button_circle.click();
await button_font.click();
await button_color.click();
+
+ let buttons = await driver.findComponents(ON.type('Button'))
+ await buttons[1].click();
+ await buttons[3].click();
+ await buttons[5].click();
+ await buttons[6].click();
+
await driver.pressBack();
await driver.pressBack();
done();
@@ -183,6 +202,91 @@ export default function IndexTest() {
done();
})
+ it('testButtonCase1', 0, async (done: Function) => {
+ let driver = Driver.create();
+ let button_list = await driver.findComponent(ON.text('Button', MatchPattern.CONTAINS));
+ expect(button_list === null).assertFalse();
+ await button_list.click();
+ let str = await getResourceString($r('app.string.ButtonCase1_title'));
+ let button_search = await driver.findComponent(ON.text(str, MatchPattern.CONTAINS));
+ expect(button_search === null).assertFalse();
+ await button_search.click();
+ let button_first = await driver.findComponent(ON.text('First', MatchPattern.CONTAINS));
+ expect(button_first === null).assertFalse();
+ await button_first.click();
+ await driver.pressBack()
+
+ let button_second = await driver.findComponent(ON.text('Second', MatchPattern.CONTAINS));
+ expect(button_second === null).assertFalse();
+ await button_second.click();
+ await driver.pressBack()
+
+ let button_third = await driver.findComponent(ON.text('Third', MatchPattern.CONTAINS));
+ expect(button_third === null).assertFalse();
+ await button_third.click();
+ await driver.pressBack()
+
+ await driver.pressBack();
+ done();
+ })
+
+ it('testButtonCase2', 0, async (done: Function) => {
+ let driver = Driver.create();
+ let button_list = await driver.findComponent(ON.text('Button', MatchPattern.CONTAINS));
+ expect(button_list === null).assertFalse();
+ await button_list.click();
+ let str = await getResourceString($r('app.string.ButtonCase2_title'));
+ let button_search = await driver.findComponent(ON.text(str, MatchPattern.CONTAINS));
+ expect(button_search === null).assertFalse();
+ await button_search.click();
+ let input_buttons = await driver.findComponents(ON.type('TextInput'))
+ let username = input_buttons[0]
+ let password = input_buttons[1]
+ let registerButton = await driver.findComponent(ON.text('Register', MatchPattern.CONTAINS));
+ let okButton = await driver.findComponent(ON.text('Ok', MatchPattern.CONTAINS));
+ expect(username === null).assertFalse();
+ expect(password === null).assertFalse();
+ expect(registerButton === null).assertFalse();
+ expect(okButton === null).assertFalse();
+ await username.inputText('username');
+ await password.inputText('password');
+ expect(await username.getText() === 'username').assertTrue();
+
+ let point = await password.getBoundsCenter();
+ await driver.mouseClick({
+ x: point.x + 300, y: point.y
+ }, MouseButton.MOUSE_BUTTON_LEFT, 0, 0);
+ expect(await password.getText() === 'password').assertTrue();
+ await registerButton.click();
+ await okButton.click();
+ await driver.pressBack();
+ await driver.pressBack();
+ await driver.pressBack();
+ done();
+ })
+
+
+ it('testHoverButtonExample', 0, async (done: Function) => {
+ let driver = Driver.create();
+ let button_list = await driver.findComponent(ON.text('Button', MatchPattern.CONTAINS));
+ expect(button_list === null).assertFalse();
+ await button_list.click();
+ let str = await getResourceString($r('app.string.HoverButtonExample_title'));
+ let button_search = await driver.findComponent(ON.text(str, MatchPattern.CONTAINS));
+ expect(button_search === null).assertFalse();
+ await button_search.click();
+
+ let floatingButton = await driver.findComponent(ON.id('Button'));
+ let stackList = await driver.findComponent(ON.id('List'));
+ expect(floatingButton === null).assertFalse();
+ expect(stackList === null).assertFalse();
+ await floatingButton.click();
+ await stackList.scrollToBottom();
+ await driver.pressBack();
+ await driver.pressBack();
+ done();
+ })
+
it('testToggleUiExample1', 0, async (done: Function) => {
let driver: Driver = Driver.create();
let button_list = await driver.findComponent(ON.text('Toggle', MatchPattern.CONTAINS));
diff --git a/ArkUIKit/ChooseComponent/ohosTest.md b/ArkUIKit/ChooseComponent/ohosTest.md
index 95d1ceb49b3fcfc428d43e99852853768433ed2e..ac419f406dae2d55a44017a4f27189100db230a2 100644
--- a/ArkUIKit/ChooseComponent/ohosTest.md
+++ b/ArkUIKit/ChooseComponent/ohosTest.md
@@ -1,5 +1,20 @@
+
+# Button 测试用例归档
+
+## 用例表
+
+| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 |
+|---------------------------------| -------------- |-------------------------------------------------------|-----------------------------------| :------- | -------- |
+| 悬浮按钮 | 设备正常运行 | 进入示例页面,点击"Button"按钮,滚动到底部,返回 | 在可以滑动的界面,滑动时按钮始终保持悬浮状态 | 是 | Pass |
+| 按钮用于启动操作 | 设备正常运行 | 进入示例页面,点击"First"按钮,返回。点击"Second"按钮,返回 。点击"Third"按钮,返回 | 可以用按钮启动任何用户界面元素,按钮会根据用户的操作触发相应的事件 | 是 | Pass |
+| 按钮用于提交表单 | 设备正常运行 | 进入示例页面,输入用户名和密码,点击"Register"按钮,返回 | 在用户登录/注册页面,使用按钮进行登录或注册操作 | 是 | Pass |
+| 按钮用于提交表单 | 设备正常运行 | 进入示例页面,输入用户名和密码,点击"Register"按钮,返回 | 在用户登录/注册页面,使用按钮进行登录或注册操作 | 是 | Pass |
+
+# Radio 测试用例归档
+
| 组件 | 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 |
|-----------------------------------| ------------ | ---------------------- |-----------| -------- | -------- |
| Radio | 首页加载测试 | 设备正常运行 | 验证基础元素展示 | 检查标题和列表组件 | Pass |
| Radio | 单选框示例示例页面加载,页面按钮响应 | 设备正常运行 | 1. 点击"单选框示例示例"。
2. 单选框示例示例页面分别点击ratio按钮:
点击"Ringing"按钮,提示词“Ringing",打印文字”Ringing mode."
点击"Vibration"按钮,提示词“Vibration",打印文字”Vibration mode."
点击"Silent"按钮,提示词“Silent",打印文字”Silent mode." | 页面加载成功
按钮点击响应正常 | Pass |
-| Radio | 单选框示例2页面 | 设备正常运行 | 点击"单选框示例2" | 页面加载成功 | Pass |
\ No newline at end of file
+| Radio | 单选框示例2页面 | 设备正常运行 | 点击"单选框示例2" | 页面加载成功 | Pass |
+
diff --git a/ArkUIKit/DialogProject/.gitignore b/ArkUIKit/DialogProject/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b
--- /dev/null
+++ b/ArkUIKit/DialogProject/.gitignore
@@ -0,0 +1,12 @@
+/node_modules
+/oh_modules
+/local.properties
+/.idea
+**/build
+/.hvigor
+.cxx
+/.clangd
+/.clang-format
+/.clang-tidy
+**/.test
+/.appanalyzer
\ No newline at end of file
diff --git a/ArkUIKit/DialogProject/README_zh.md b/ArkUIKit/DialogProject/README_zh.md
index fe49c9e7249fb1354c5d050d61cad272ccf3e855..71f6b5827b5a76539f52cafdee63c5df2ce243f9 100644
--- a/ArkUIKit/DialogProject/README_zh.md
+++ b/ArkUIKit/DialogProject/README_zh.md
@@ -2,7 +2,7 @@
### 介绍
-本示例通过使用[ArkUI指南文档](https://gitcode.com/openharmony/docs/tree/master/zh-cn/application-dev/ui)中各场景的开发示例,展示在工程中,帮助开发者更好地理解ArkUI提供的组件及组件属性并合理使用。该工程中展示的代码详细描述可查如下链接:
+本示例通过使用[ArkUI指南文档](https://gitCode.com/openharmony/docs/tree/master/zh-cn/application-dev/ui)中各场景的开发示例,展示在工程中,帮助开发者更好地理解ArkUI提供的组件及组件属性并合理使用。该工程中展示的代码详细描述可查如下链接:
1. [不依赖UI组件的全局自定义弹出框 (openCustomDialog)](https://gitcode.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/ui/arkts-uicontext-custom-dialog.md)。
2. [基础自定义弹出框 (CustomDialog)](https://gitcode.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/ui/arkts-common-components-custom-dialog.md)。
@@ -11,6 +11,7 @@
5. [气泡提示 (Popup)](https://gitcode.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/ui/arkts-popup-and-menu-components-popup.md)
6. [即时反馈 (Toast)](https://gitcode.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/ui/arkts-create-toast.md)
7. [设置浮层 (OverlayManager)](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/ui/arkts-create-overlaymanager.md)
+8. [弹出框蒙层控制](https://gitcode.com/openharmony/docs/blob/OpenHarmony-6.0-Release/zh-cn/application-dev/ui/arkts-dialog-mask.md)
### 效果预览
| 首页 | 弹窗类组件目录 | 自定义弹窗示例 | | |
@@ -34,28 +35,50 @@ entry/src/main/ets/
|---pages
| |---customdialog //自定义弹出框
| | |---CreateCustomDialog.ets
+| | |---CreateCustomDialog1.ets
| | |---DialogAnimation.ets
+| | |---DialogAnimation1.ets
+| | |---DialogAvoidSoftKeyboard.ets
| | |---DialogInteraction.ets
| | |---DialogInteraction1.ets
+| | |---DialogInteraction2.ets
+| | |---DialogInteraction3.ets
| | |---DialogStyle.ets
+| | |---DialogStyle1.ets
+| | |---DialogWithPhysicalBack.ets
+| | |---GetDialogStatus.ets
| | |---Index.ets
+| | |---Index2.ets
| | |---NestDialog.ets
+| | |---NestDialog1.ets
| |---fixedstyledialog //固定样式弹出框
| | |---ActionSheet.ets
| | |---AlertDialog.ets
| | |---CalendarPickerDialog.ets
| | |---DatePickerDialog.ets
+| | |---DatePickerCustomDialog.ets
| | |---Index.ets
| | |---ShowActionMenu.ets
| | |---ShowDialog.ets
| | |---TextPickerDialog.ets
| | |---TimePickerDialog.ets
+| |---maskdialog //弹出框蒙层控制
+| | |---CustomDialogAnimation.ets
+| | |---CustomDialogControl.ets
+| | |---Index.ets
| |---Menu //菜单
+| | |---BindComponentMenu.ets //基于绑定组件指定位置弹出菜单
| | |---CreateMenu.ets
+| | |---EventTransSubWindowMenu.ets //控制子窗菜单的事件透传
| | |---Index.ets
+| | |---PopVibrateMenu.ets //菜单弹出时振动效果
+| | |---SupportAvoidCentralAxisMenu.ets //菜单支持避让中轴
| |---opencustomdialog //不依赖UI组件的全局自定义弹出框
| | |---Index.ets
| | |---openCustomDialog.ets
+| | |---customDialogComponentWithTransition.ets
+| | |---customDialogWithKeyboardAvoidDistance.ets
+| | |---OpenDialogAndUpdate.ets
| |---OverlayManager //设置浮层
| | |---Index.ets
| | |---OverlayManagerDemo1.ets
@@ -66,8 +89,11 @@ entry/src/main/ets/
| | |---CustomPopup.ets
| | |---Index.ets
| | |---PopupAnimation.ets
+| | |---PopupAvoidSoftKeyboard.ets //气泡避让软键盘示例
+| | |---PopupPolymorphicEffect.ets //设置气泡内的多态效果示例
| | |---PopupStateChange.ets
| | |---PopupStyle.ets
+| | |---PopupSupportedAvoidAxis.ets //气泡支持避让中轴示例
| | |---TextPrompts.ets
| |---Toast //即使反馈
| | |---CreateToast.ets
@@ -85,15 +111,56 @@ entry/src/ohosTest/
1. 设置浮层(OverlayManager):可以通过使用UIContext中的getOverlayManager方法获取当前UI上下文关联的OverlayManager对象,再通过该对象调用对应方法。
- * 在OverlayManager上新增指定节点、删除指定节点、显示所有节点和隐藏所有节点。代码参考[OverlayManagerDemo1.ets](https://gitcode.com/openharmony/applications_app_samples/tree/master/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/OverlayManager/OverlayManagerDemo1.ets)
+ * 在OverlayManager上新增指定节点、删除指定节点、显示所有节点和隐藏所有节点。代码参考[OverlayManagerDemo1.ets](https://gitcode.com/openharmony/applications_app_samples/tree/master/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/OverlayManager/OverlayManagerDemo1.ets)
- * 显示一个始终在屏幕左侧的悬浮球,点击可以弹出alertDialog弹窗。代码参考[OverlayManagerDemo2.ets](https://gitcode.com/openharmony/applications_app_samples/tree/master/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/OverlayManager/OverlayManagerDemo2.ets)
+ * 显示一个始终在屏幕左侧的悬浮球,点击可以弹出alertDialog弹窗。代码参考[OverlayManagerDemo2.ets](https://gitcode.com/openharmony/applications_app_samples/tree/master/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/OverlayManager/OverlayManagerDemo2.ets)
- * 调用UIContext中getOverlayManager方法获取OverlayManager对象,并利用该对象在指定层级上新增指定节点(addComponentContentWithOrder),层次高的浮层会覆盖在层级低的浮层之上。代码参考[OverlayManagerDemo3.ets](https://gitcode.com/openharmony/applications_app_samples/tree/master/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/OverlayManager/OverlayManagerDemo3.ets)
+ * 调用UIContext中getOverlayManager方法获取OverlayManager对象,并利用该对象在指定层级上新增指定节点(addComponentContentWithOrder),层次高的浮层会覆盖在层级低的浮层之上。代码参考[OverlayManagerDemo3.ets](https://gitcode.com/openharmony/applications_app_samples/tree/master/code/DocsSample/ArkUISample/DialogProject/entry/src/main/ets/pages/OverlayManager/OverlayManagerDemo3.ets)
-### 相关权限
+2. 气泡提示(Popup)
-不涉及。
+ * 气泡分为两种类型,一种是系统提供的气泡PopupOptions,一种是开发者可以自定义的气泡CustomPopupOptions。其中,PopupOptions通过配置primaryButton和secondaryButton来设置带按钮的气泡;CustomPopupOptions通过配置builder来设置自定义的气泡。其中系统提供的气泡PopupOptions,字体的最大放大倍数为2。
+
+ * 气泡可以通过配置mask来实现模态和非模态窗口,mask为true或者颜色值的时候,气泡为模态窗口,mask为false时,气泡为非模态窗口。
+
+ * 多个气泡同时弹出时,子窗内显示的气泡比主窗内显示的气泡层级高,所处窗口相同时,后面弹出的气泡层级比先弹出的气泡层级高。
+
+3. 菜单控制(Menu)
+
+ * Menu是菜单接口,一般用于鼠标右键弹窗、点击弹窗等。具体用法请参考菜单控制。
+
+ * 使用bindContextMenu并设置预览图,菜单弹出时有蒙层,此时为模态。
+
+ * 使用bindMenu或bindContextMenu未设置预览图时,菜单弹出无蒙层,此时为非模态。
+
+4. 基础自定义弹出框 (CustomDialog)
+
+ * CustomDialog是自定义弹出框,可用于广告、中奖、警告、软件更新等与用户交互响应操作。
+
+ * 开发者可以通过CustomDialogController类显示自定义弹出框。具体用法请参考自定义弹出框。
+
+ * 默认为模态弹窗且有蒙层,不可与蒙层下方控件进行交互(不支持点击和手势等向下透传)。
+
+ * 可以通过配置CustomDialogControllerOptions中的isModal属性来实现模态和非模态弹窗,详细说明可参考弹窗的种类。
+
+5. 不依赖UI组件的全局自定义弹出框 (openCustomDialog)
+
+ * 推荐使用UIContext中获取到的PromptAction对象提供的openCustomDialog接口在相对应用复杂的场景来实现自定义弹出框,相较于CustomDialogController优势点在于页面解耦,支持动态刷新。
+
+ * 弹出框(openCustomDialog)默认为模态弹窗且有蒙层,不可与蒙层下方控件进行交互(不支持点击和手势等向下透传)。
+
+ * 可以通过配置promptAction.BaseDialogOptions类型中的isModal属性来实现模态和非模态弹窗,详细说明可参考弹窗的种类。
+
+ * 当isModal为true时,弹出框为模态弹窗,且弹窗周围的蒙层区不支持透传。isModal为false时,弹出框为非模态弹窗,且弹窗周围的蒙层区可以透传。因此如果需要同时允许弹出框的交互和弹出框外页面的交互行为,需要将弹出框设置为非模态。
+
+5. 弹出框蒙层控制(MaskDialog)
+
+ * 开发者对弹出框的定制不仅限于弹出框里的内容,对弹出框蒙层的定制需求也逐渐增加。
+
+ * 本文介绍ArkUI弹出框的蒙层控制,包括点击蒙层时是否消失、蒙层区域、蒙层颜色和蒙层动画等特性。
+
+### 相关权限
+ 不涉及。
### 依赖
@@ -103,9 +170,9 @@ entry/src/ohosTest/
1.本示例仅支持标准系统上运行, 支持设备:RK3568。
-2.本示例为Stage模型,支持API18版本SDK,版本号:5.1.0.56,镜像版本号:OpenHarmony_5.1.0.56。
+2.本示例为Stage模型,支持API22版本full-SDK,版本号:6.0.0.47,镜像版本号:OpenHarmony_6.0.0 Release。
-3.本示例需要使用DevEco Studio NEXT Developer Preview2 (Build Version: 5.0.5.306, built on December 12, 2024)及以上版本才可编译运行。
+3.本示例需要使用DevEco Studio 6.0.0 Release (Build Version: 6.0.0.858, built on September 24, 2025)及以上版本才可编译运行。
### 下载
@@ -115,6 +182,6 @@ entry/src/ohosTest/
git init
git config core.sparsecheckout true
echo code/DocsSample/ArkUISample/DialogProject > .git/info/sparse-checkout
-git remote add origin https://gitcode.com/openharmony/applications_app_samples.git
+git remote add origin https://gitCode.com/openharmony/applications_app_samples.git
git pull origin master
````
\ No newline at end of file
diff --git a/ArkUIKit/DialogProject/entry/src/main/ets/common/PromptActionClass1.ts b/ArkUIKit/DialogProject/entry/src/main/ets/common/PromptActionClass1.ts
new file mode 100644
index 0000000000000000000000000000000000000000..904a0d4000a9f083b1f5ef713dcf951dc3f527e2
--- /dev/null
+++ b/ArkUIKit/DialogProject/entry/src/main/ets/common/PromptActionClass1.ts
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2025 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// [Start prompt_action_class1]
+// PromptActionClass1.ets
+import { BusinessError } from '@kit.BasicServicesKit';
+import { ComponentContent, promptAction, UIContext } from '@kit.ArkUI';
+
+export class PromptActionClass1 {
+ static ctx: UIContext;
+ static contentNode: ComponentContent