1e41f4b71Sopenharmony_ci# Popup 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ciYou can bind the **Popup** attribute to a component to create a popup, specifying its content and interaction logic, and display state. It is mainly used for screen recording and message notification. 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ciPopups can be defined with [PopupOptions](../reference/arkui-ts/ts-universal-attributes-popup.md#popupoptions) or [CustomPopupOptions](../reference/arkui-ts/ts-universal-attributes-popup.md#custompopupoptions8). In **PopupOptions**, you can set **primaryButton** and **secondaryButton** to include buttons in the popup. In **CustomPopupOptions**, you can create a custom popup through the [builder](../quick-start/arkts-builder.md) parameter. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci## Text Popup 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ciText popups are usually used to display text only and do not allow for user interactions. Bind the **Popup** attribute to a component. When the **show** parameter in the **bindPopup** attribute is set to **true**, a popup is displayed. 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ciIf you bind the **Popup** attribute to a **\<Button>** component, each time the **\<Button>** button is clicked, the Boolean value of **handlePopup** changes. When it changes to **true**, the popup is displayed. 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci```ts 17e41f4b71Sopenharmony_ci@Entry 18e41f4b71Sopenharmony_ci@Component 19e41f4b71Sopenharmony_cistruct PopupExample { 20e41f4b71Sopenharmony_ci @State handlePopup: boolean = false 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci build() { 23e41f4b71Sopenharmony_ci Column() { 24e41f4b71Sopenharmony_ci Button('PopupOptions') 25e41f4b71Sopenharmony_ci .onClick(() => { 26e41f4b71Sopenharmony_ci this.handlePopup = !this.handlePopup 27e41f4b71Sopenharmony_ci }) 28e41f4b71Sopenharmony_ci .bindPopup(this.handlePopup, { 29e41f4b71Sopenharmony_ci message: 'This is a popup with PopupOptions', 30e41f4b71Sopenharmony_ci }) 31e41f4b71Sopenharmony_ci }.width('100%').padding({ top: 5 }) 32e41f4b71Sopenharmony_ci } 33e41f4b71Sopenharmony_ci} 34e41f4b71Sopenharmony_ci``` 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci## Adding an Event for Popup State Changes 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ciYou can use the **onStateChange** parameter to add an event callback for popup state changes, so as to determine the current state of the popup. 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci```ts 44e41f4b71Sopenharmony_ci@Entry 45e41f4b71Sopenharmony_ci@Component 46e41f4b71Sopenharmony_cistruct PopupExample { 47e41f4b71Sopenharmony_ci @State handlePopup: boolean = false 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci build() { 50e41f4b71Sopenharmony_ci Column() { 51e41f4b71Sopenharmony_ci Button('PopupOptions') 52e41f4b71Sopenharmony_ci .onClick(() => { 53e41f4b71Sopenharmony_ci this.handlePopup = !this.handlePopup 54e41f4b71Sopenharmony_ci }) 55e41f4b71Sopenharmony_ci .bindPopup(this.handlePopup, { 56e41f4b71Sopenharmony_ci message: 'This is a popup with PopupOptions', 57e41f4b71Sopenharmony_ci onStateChange: (e)=> {// Return the current popup state. 58e41f4b71Sopenharmony_ci if (!e.isVisible) { 59e41f4b71Sopenharmony_ci this.handlePopup = false 60e41f4b71Sopenharmony_ci } 61e41f4b71Sopenharmony_ci } 62e41f4b71Sopenharmony_ci }) 63e41f4b71Sopenharmony_ci }.width('100%').padding({ top: 5 }) 64e41f4b71Sopenharmony_ci } 65e41f4b71Sopenharmony_ci} 66e41f4b71Sopenharmony_ci``` 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci## Popup with a Button 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ciYou can add a maximum of two buttons to a popup through the **primaryButton** and **secondaryButton** attributes. For each of the buttons, you can set the **action** parameter to specify the operation to be triggered. 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci```ts 75e41f4b71Sopenharmony_ci@Entry 76e41f4b71Sopenharmony_ci@Component 77e41f4b71Sopenharmony_cistruct PopupExample22 { 78e41f4b71Sopenharmony_ci @State handlePopup: boolean = false 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci build() { 81e41f4b71Sopenharmony_ci Column() { 82e41f4b71Sopenharmony_ci Button('PopupOptions').margin({ top: 200 }) 83e41f4b71Sopenharmony_ci .onClick(() => { 84e41f4b71Sopenharmony_ci this.handlePopup = !this.handlePopup 85e41f4b71Sopenharmony_ci }) 86e41f4b71Sopenharmony_ci .bindPopup(this.handlePopup, { 87e41f4b71Sopenharmony_ci message: 'This is a popup with PopupOptions', 88e41f4b71Sopenharmony_ci primaryButton: { 89e41f4b71Sopenharmony_ci value: 'Confirm', 90e41f4b71Sopenharmony_ci action: () => { 91e41f4b71Sopenharmony_ci this.handlePopup = !this.handlePopup 92e41f4b71Sopenharmony_ci console.info('confirm Button click') 93e41f4b71Sopenharmony_ci } 94e41f4b71Sopenharmony_ci }, 95e41f4b71Sopenharmony_ci secondaryButton: { 96e41f4b71Sopenharmony_ci value: 'Cancel', 97e41f4b71Sopenharmony_ci action: () => { 98e41f4b71Sopenharmony_ci this.handlePopup = !this.handlePopup 99e41f4b71Sopenharmony_ci } 100e41f4b71Sopenharmony_ci }, 101e41f4b71Sopenharmony_ci onStateChange: (e) => { 102e41f4b71Sopenharmony_ci if (!e.isVisible) { 103e41f4b71Sopenharmony_ci this.handlePopup = false 104e41f4b71Sopenharmony_ci } 105e41f4b71Sopenharmony_ci } 106e41f4b71Sopenharmony_ci }) 107e41f4b71Sopenharmony_ci }.width('100%').padding({ top: 5 }) 108e41f4b71Sopenharmony_ci } 109e41f4b71Sopenharmony_ci} 110e41f4b71Sopenharmony_ci``` 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ci 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_ci## Custom Popup 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_ciYou can create a custom popup with **CustomPopupOptions**, defining custom content in \@Builder. In addition, you can use parameters such as **popupColor** to control the popup style. 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_ci```ts 121e41f4b71Sopenharmony_ci@Entry 122e41f4b71Sopenharmony_ci@Component 123e41f4b71Sopenharmony_cistruct Index { 124e41f4b71Sopenharmony_ci @State customPopup: boolean = false 125e41f4b71Sopenharmony_ci // Define the popup content in the popup builder. 126e41f4b71Sopenharmony_ci @Builder popupBuilder() { 127e41f4b71Sopenharmony_ci Row({ space: 2 }) { 128e41f4b71Sopenharmony_ci Image($r("app.media.icon")).width(24).height(24).margin({ left: 5 }) 129e41f4b71Sopenharmony_ci Text('This is Custom Popup').fontSize(15) 130e41f4b71Sopenharmony_ci }.width(200).height(50).padding(5) 131e41f4b71Sopenharmony_ci } 132e41f4b71Sopenharmony_ci build() { 133e41f4b71Sopenharmony_ci Column() { 134e41f4b71Sopenharmony_ci Button('CustomPopupOptions') 135e41f4b71Sopenharmony_ci .position({x:100,y:200}) 136e41f4b71Sopenharmony_ci .onClick(() => { 137e41f4b71Sopenharmony_ci this.customPopup = !this.customPopup 138e41f4b71Sopenharmony_ci }) 139e41f4b71Sopenharmony_ci .bindPopup(this.customPopup, { 140e41f4b71Sopenharmony_ci builder: this.popupBuilder, // Content of the popup. 141e41f4b71Sopenharmony_ci placement:Placement.Bottom, // Position of the popup. 142e41f4b71Sopenharmony_ci popupColor:Color.Pink // Background color of the popup. 143e41f4b71Sopenharmony_ci onStateChange: (e) => { 144e41f4b71Sopenharmony_ci console.info(JSON.stringify(e.isVisible)) 145e41f4b71Sopenharmony_ci if (!e.isVisible) { 146e41f4b71Sopenharmony_ci this.customPopup = false 147e41f4b71Sopenharmony_ci } 148e41f4b71Sopenharmony_ci } 149e41f4b71Sopenharmony_ci }) 150e41f4b71Sopenharmony_ci } 151e41f4b71Sopenharmony_ci .height('100%') 152e41f4b71Sopenharmony_ci } 153e41f4b71Sopenharmony_ci} 154e41f4b71Sopenharmony_ci``` 155e41f4b71Sopenharmony_ci 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_ciTo place the popup in a specific position, set the **placement** parameter. The popup builder triggers a popup message to instruct the user to complete the operation. 158e41f4b71Sopenharmony_ci 159e41f4b71Sopenharmony_ci 160e41f4b71Sopenharmony_ci 161