The HDS component supports the immersive light material capability since version 6.1.0(23).
The system adaptive immersive light effect is recommended. The system dynamically adjusts the material effect of the component based on the computing power of the current device, achieving the optimal balance between performance and display effect.
Import required modules.
import { HdsNavigation, HdsNavigationTitleMode, HdsTabs, HdsTabsController, HdsNavigationMenuContentOptions, ScrollEffectType, hdsMaterial } from '@kit.UIDesignKit';
import { SymbolGlyphModifier } from '@kit.ArkUI'; Create the HDS navigation and bottom tab components. The navigation title bar contains one back button and three function buttons, and the bottom tab contains three sub-items.
The following sample code sets the immersive light effect for the bottom tab and the four buttons on the title bar. This effect will be automatically adjusted based on the system capability.
// Example of adaptive immersive light effect
@Entry
@Component
export struct AdaptiveIndex {
private scrollerForScroll: Scroller = new Scroller();
private controller: HdsTabsController = new HdsTabsController();
private menus: HdsNavigationMenuContentOptions = {
value: [{
content: {
label: 'menu1',
icon: $r('sys.symbol.square_and_pencil')
}
}, {
content: {
label: 'menu2',
icon: $r('sys.symbol.star')
}
},{
content: {
label: 'menu3',
icon: $r('sys.symbol.more')
}
}
]
};
build() {
HdsNavigation() {
HdsTabs({ controller: this.controller }) {
ForEach(MENU_CONFIG, (item: MenuItem) => {
TabContent() {
Stack() {
Scroll(this.scrollerForScroll) {
Column() {
Image($r('app.media.scenery01')).width('100%') // scenery is a custom resource. You need to replace it with your local resource.
}
}
.clipContent(ContentClipMode.SAFE_AREA)
.height('100%')
}
}
.tabBar(new BottomTabBarStyle({
normal: item.symbolGlyph, selected: item.symbolGlyph1
}, item.label))
})
}
.barOverlap(true)
.vertical(false)
.barPosition(BarPosition.End)
.barFloatingStyle({
barBottomMargin: 28,
// Set immersive light effect: The **ADAPTIVE** type represents an adaptive system material, and the **ADAPTIVE** level indicates that the material application strategy is dynamically determined by the system based on device performance.
systemMaterialEffect: {
materialType: hdsMaterial.MaterialType.ADAPTIVE,
materialLevel: hdsMaterial.MaterialLevel.ADAPTIVE //: The immersive light effect of the floating tab at the bottom is automatically adapted based on the system policy.
}
})
}
.mode(NavigationMode.Stack)
.titleBar({
content: {
title: {
mainTitle: 'MainTitle',
},
menu: this.menus,
},
style: {
scrollEffectOpts: {
enableScrollEffect: false,
scrollEffectType: ScrollEffectType.GRADIENT_BLUR,
},
// Set immersive light effect: The **ADAPTIVE** type represents an adaptive system material, and the **ADAPTIVE** level indicates that the material application strategy is dynamically determined by the system based on device performance.
systemMaterialEffect: {
materialType: hdsMaterial.MaterialType.ADAPTIVE,
materialLevel: hdsMaterial.MaterialLevel.ADAPTIVE // The immersive light effect for the title bar buttons adapts to the system policy.
},
},
avoidLayoutSafeArea: false,
enableComponentSafeArea: false
})
.bindToScrollable([this.scrollerForScroll])
.hideBackButton(false)
.titleMode(HdsNavigationTitleMode.MINI)
.ignoreLayoutSafeArea([LayoutSafeAreaType.SYSTEM], [LayoutSafeAreaEdge.TOP, LayoutSafeAreaEdge.BOTTOM])
}
}
interface MenuItem {
symbolGlyph: SymbolGlyphModifier,
symbolGlyph1: SymbolGlyphModifier,
label: string,
defaultBgColor: ResourceColor,
hoverBgColor: ResourceColor,
pressBgColor: ResourceColor,
};
const MENU_CONFIG: MenuItem[] = [
{
symbolGlyph: new SymbolGlyphModifier($r('sys.symbol.alarm_fill_1')).renderingStrategy(SymbolRenderingStrategy.MULTIPLE_COLOR)
.fontColor([$r('sys.color.ohos_id_color_bottom_tab_icon_off'),
$r('sys.color.ohos_id_color_bottom_tab_icon_auxcolor_off02')]),
symbolGlyph1: new SymbolGlyphModifier($r('sys.symbol.alarm_fill_1')).renderingStrategy(SymbolRenderingStrategy.MULTIPLE_COLOR)
.fontColor([$r('sys.color.ohos_id_color_activated'), $r('sys.color.ohos_id_color_primary_contrary')]),
label: 'Alarm clock',
defaultBgColor: Color.Transparent,
hoverBgColor: $r('sys.color.ohos_id_color_hover'),
pressBgColor: $r('sys.color.ohos_id_color_click_effect')
},
{
symbolGlyph: new SymbolGlyphModifier($r('sys.symbol.worldclock_fill_2')).renderingStrategy(SymbolRenderingStrategy.MULTIPLE_COLOR)
.fontColor([$r('sys.color.ohos_id_color_bottom_tab_icon_off'),
$r('sys.color.ohos_id_color_bottom_tab_icon_auxcolor_off02')]),
symbolGlyph1: new SymbolGlyphModifier($r('sys.symbol.worldclock_fill_2')).renderingStrategy(SymbolRenderingStrategy.MULTIPLE_COLOR)
.fontColor([$r('sys.color.ohos_id_color_activated'), $r('sys.color.ohos_id_color_primary_contrary')]),
label: 'Clock',
defaultBgColor: Color.Transparent,
hoverBgColor: $r('sys.color.ohos_id_color_hover'),
pressBgColor: $r('sys.color.ohos_id_color_click_effect')
},
{
symbolGlyph: new SymbolGlyphModifier($r('sys.symbol.stopwatch_2')).renderingStrategy(SymbolRenderingStrategy.MULTIPLE_COLOR)
.fontColor([$r('sys.color.ohos_id_color_bottom_tab_icon_off'),
$r('sys.color.ohos_id_color_bottom_tab_icon_auxcolor_off02')]),
symbolGlyph1: new SymbolGlyphModifier($r('sys.symbol.stopwatch_2')).renderingStrategy(SymbolRenderingStrategy.MULTIPLE_COLOR)
.fontColor([$r('sys.color.ohos_id_color_activated'), $r('sys.color.ohos_id_color_primary_contrary')]),
label: 'Stopwatch',
defaultBgColor: Color.Transparent,
hoverBgColor: $r('sys.color.ohos_id_color_hover'),
pressBgColor: $r('sys.color.ohos_id_color_click_effect')
}
]; To use custom immersive light effects, call the getSystemMaterialTypes() API to query the material capabilities supported by the current device, and then select the corresponding material effect based on the query result.
Import required modules.
import { HdsNavigation, HdsNavigationTitleMode, HdsTabs, HdsTabsController, HdsNavigationMenuContentOptions, ScrollEffectType, hdsMaterial } from '@kit.UIDesignKit';
import { SymbolGlyphModifier } from '@kit.ArkUI'; Create the HDS navigation and bottom tab components. The navigation title bar contains one back button and three function buttons, and the bottom tab contains three sub-items.
The following sample code sets the immersive light effect for the bottom tab and the four buttons on the title bar, and customizes the dynamic display effect based on the material capabilities supported by the device.
// Example of customized immersive light effect
@Entry
@Component
export struct CustomIndex {
private scrollerForScroll: Scroller = new Scroller();
private controller: HdsTabsController = new HdsTabsController();
@State customMaterialLevel: hdsMaterial.MaterialLevel = hdsMaterial.MaterialLevel.EXQUISITE;
private menus: HdsNavigationMenuContentOptions = {
value: [{
content: {
label: 'menu1',
icon: $r('sys.symbol.square_and_pencil')
}
}, {
content: {
label: 'menu2',
icon: $r('sys.symbol.star')
}
},{
content: {
label: 'menu3',
icon: $r('sys.symbol.more')
}
}
]
};
aboutToAppear(): void {
// Obtain the material types supported by the system to select a proper material level based on the device capability.
let materialTypes: Array<hdsMaterial.MaterialType> = hdsMaterial.getSystemMaterialTypes();
if (materialTypes.indexOf(hdsMaterial.MaterialType.IMMERSIVE) < 0) {
// If the current device does not support the **IMMERSIVE** material type, use the **SMOOTH** effect to optimize performance and reduce the risks of stuttering and overheating.
this.customMaterialLevel = hdsMaterial.MaterialLevel.SMOOTH;
}
}
build() {
HdsNavigation() {
HdsTabs({ controller: this.controller }) {
ForEach(MENU_CONFIG, (item: MenuItem) => {
TabContent() {
Stack() {
Scroll(this.scrollerForScroll) {
Column() {
Image($r('app.media.scenery01')).width('100%') // scenery is a custom resource. You need to replace it with your local resource.
}
}
.clipContent(ContentClipMode.SAFE_AREA)
.height('100%')
}
}
.tabBar(new BottomTabBarStyle({
normal: item.symbolGlyph, selected: item.symbolGlyph1
}, item.label))
})
}
.barOverlap(true)
.vertical(false)
.barPosition(BarPosition.End)
.barFloatingStyle({
barBottomMargin: 28,
systemMaterialEffect: {
materialType: hdsMaterial.MaterialType.ADAPTIVE,
materialLevel: this.customMaterialLevel // Custom immersive light effect for floating tab at the bottom.
}
})
}
.mode(NavigationMode.Stack)
.titleBar({
content: {
title: {
mainTitle: 'MainTitle',
},
menu: this.menus,
},
style: {
scrollEffectOpts: {
enableScrollEffect: false,
scrollEffectType: ScrollEffectType.GRADIENT_BLUR,
},
systemMaterialEffect: {
materialType: hdsMaterial.MaterialType.ADAPTIVE,
materialLevel: this.customMaterialLevel // Custom immersive light effect for the buttons in the title bar.
},
},
avoidLayoutSafeArea: false,
enableComponentSafeArea: false
})
.bindToScrollable([this.scrollerForScroll])
.hideBackButton(false)
.titleMode(HdsNavigationTitleMode.MINI)
.ignoreLayoutSafeArea([LayoutSafeAreaType.SYSTEM], [LayoutSafeAreaEdge.TOP, LayoutSafeAreaEdge.BOTTOM])
}
}
interface MenuItem {
symbolGlyph: SymbolGlyphModifier,
symbolGlyph1: SymbolGlyphModifier,
label: string,
defaultBgColor: ResourceColor,
hoverBgColor: ResourceColor,
pressBgColor: ResourceColor,
};
const MENU_CONFIG: MenuItem[] = [
{
symbolGlyph: new SymbolGlyphModifier($r('sys.symbol.alarm_fill_1')).renderingStrategy(SymbolRenderingStrategy.MULTIPLE_COLOR)
.fontColor([$r('sys.color.ohos_id_color_bottom_tab_icon_off'),
$r('sys.color.ohos_id_color_bottom_tab_icon_auxcolor_off02')]),
symbolGlyph1: new SymbolGlyphModifier($r('sys.symbol.alarm_fill_1')).renderingStrategy(SymbolRenderingStrategy.MULTIPLE_COLOR)
.fontColor([$r('sys.color.ohos_id_color_activated'), $r('sys.color.ohos_id_color_primary_contrary')]),
label: 'Alarm clock',
defaultBgColor: Color.Transparent,
hoverBgColor: $r('sys.color.ohos_id_color_hover'),
pressBgColor: $r('sys.color.ohos_id_color_click_effect')
},
{
symbolGlyph: new SymbolGlyphModifier($r('sys.symbol.worldclock_fill_2')).renderingStrategy(SymbolRenderingStrategy.MULTIPLE_COLOR)
.fontColor([$r('sys.color.ohos_id_color_bottom_tab_icon_off'),
$r('sys.color.ohos_id_color_bottom_tab_icon_auxcolor_off02')]),
symbolGlyph1: new SymbolGlyphModifier($r('sys.symbol.worldclock_fill_2')).renderingStrategy(SymbolRenderingStrategy.MULTIPLE_COLOR)
.fontColor([$r('sys.color.ohos_id_color_activated'), $r('sys.color.ohos_id_color_primary_contrary')]),
label: 'Clock',
defaultBgColor: Color.Transparent,
hoverBgColor: $r('sys.color.ohos_id_color_hover'),
pressBgColor: $r('sys.color.ohos_id_color_click_effect')
},
{
symbolGlyph: new SymbolGlyphModifier($r('sys.symbol.stopwatch_2')).renderingStrategy(SymbolRenderingStrategy.MULTIPLE_COLOR)
.fontColor([$r('sys.color.ohos_id_color_bottom_tab_icon_off'),
$r('sys.color.ohos_id_color_bottom_tab_icon_auxcolor_off02')]),
symbolGlyph1: new SymbolGlyphModifier($r('sys.symbol.stopwatch_2')).renderingStrategy(SymbolRenderingStrategy.MULTIPLE_COLOR)
.fontColor([$r('sys.color.ohos_id_color_activated'), $r('sys.color.ohos_id_color_primary_contrary')]),
label: 'Stopwatch',
defaultBgColor: Color.Transparent,
hoverBgColor: $r('sys.color.ohos_id_color_hover'),
pressBgColor: $r('sys.color.ohos_id_color_click_effect')
}
]; Display of Immersive Light Material Effects 