This content originally appeared on DEV Community and was authored by ShuGang Zhou
HarmonyOS 5 News App Navigation Bar Implementation
Abstract
This article introduces the implementation of the navigation bar in the HarmonyOS 5.0 news application. It uses the ArkTS language to implement the NavBarBuilder
and BarButton
components to control the layout and style of the navigation bar.
Implementation Steps
- Define the
NavBarBuilder
builder. - Define the
BarButton
component. - Configure button styles and layouts.
Code Implementation
1. Define the NavBarBuilder
Builder
@Builder
NavBarBuilder() {
Row({ space: 10 }) {
BarButton({ icon: $r('sys.media.ohos_ic_public_email') , type: 'normal' })
Blank()
BarButton({ icon: $r('sys.media.ohos_ic_public_search_filled') , type: 'normal' })
BarButton({ icon: $r('sys.media.ohos_ic_public_clock') , type: 'normal' })
}
.padding(15)
.width('100%')
}
2. Define the BarButton
Component
@Component
struct BarButton {
icon: ResourceStr = ''
type: 'transparent' | 'normal' = 'transparent'
build() {
Row() {
Image(this.icon)
.width(24)
.height(24)
.fillColor(this.type === 'transparent' ? Color.White : Color.Black)
}
.justifyContent(FlexAlign.Center)
.width(40)
.aspectRatio(1)
.borderRadius(22)
.backgroundColor(this.type === 'transparent' ? '#45FFFFFF' : '#f3f4f5')
}
}
Summary
Key knowledge points include the use of the @Builder
decorator, component definition, the use of the Row
layout container, and the configuration of style attributes. By combining the NavBarBuilder
and BarButton
components, a flexible and configurable navigation bar is implemented.
This content originally appeared on DEV Community and was authored by ShuGang Zhou

ShuGang Zhou | Sciencx (2025-06-27T03:44:45+00:00) HarmonyOS5-NewsAPP-NavBar. Retrieved from https://www.scien.cx/2025/06/27/harmonyos5-newsapp-navbar/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.