my.setNavigationBar allows you to customize the navigation bar (top bar) of your Mini Program by setting the title, background color, border color, or displaying a custom image. This API provides dynamic control over your Mini Program's header appearance.
my.setNavigationBar({
title: 'hello',
backgroundColor: '#108ee9',
success() {
my.alert({
content: 'Success',
});
},
fail() {
my.alert({
content: 'Failed',
});
},
});
| Property | Type | Required | Description |
|---|---|---|---|
title | String | No | Navigation bar title. |
image | String | No | Picture link address, must be https. Use 3x high-definition pictures. If the image is set, the title parameter is inactive. Currently, SVG images are not supported. |
backgroundColor | String | No | Navigation bar background color, supporting hex color value. |
borderBottomColor | String | No | Navigation bar bottom border color, supporting hex color value. If the backgroundColor is set, the borderBottomColor does not take effect. The backgroundColor is used by default. |
reset | Boolean | No | Whether the navigation bar is reset to the default color, false by default. |
success | Function | No | Callback function upon call success. |
fail | Function | No | Callback function upon call failure. |
complete | Function | No | Callback function upon call completion (to be executed upon either call success or failure). |
image is set, the title parameter becomes inactive. Choose one or the other.backgroundColor and borderBottomColor (e.g., '#108ee9', '#FFFFFF').backgroundColor is set, borderBottomColor will not take effect and the background color will be used for the border.reset: true to restore the navigation bar to its default appearance.my.setNavigationBar({
title: 'Payment Confirmation',
backgroundColor: '#108ee9'
});
my.setNavigationBar({
image: 'https://example.com/images/header-3x.png',
backgroundColor: '#FFFFFF'
});
my.setNavigationBar({
reset: true
});