1、HarmonyOS 狀態欄怎么控制顯示于隱藏,設置狀態欄顏色,子顏色等控制?
顯示與隱藏 可以設置沉浸式,隱藏的話可以退出沉靜式,在子窗口打開的頁面 aboutToAppear 方法中設置沉浸式
aboutToAppear(): void {// 設置沉浸式window.getLastWindow(getContext(this), (err, windowBar) => {windowBar.setWindowLayoutFullScreen(true);// windowBar.setWindowSystemBarEnable([])
})
}
aboutToDisappear(): void {// 退出沉浸式window.getLastWindow(getContext(this), (err, windowBar) => {windowBar.setWindowLayoutFullScreen(false);// windowBar.setWindowSystemBarEnable([])
})
}
參考鏈接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5#setwindowlayoutfullscreen9
設置狀態欄的背景:SystemBarProperties,參考鏈接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5#setwindowlayoutfullscreen9
或者使用:
onWindowStageCreate(windowStage: window.WindowStage): void {// Main window is created, set main page for this abilityhilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');windowStage.loadContent('pages/APage', (err) => {if (err.code) {hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');return;
}
windowStage.getMainWindowSync().setWindowBackgroundColor('#00ff33') ##此處添加
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.');
});
}
2、HarmonyOS SegmentButton 點擊事件回調是哪個? onclick無回調?
用戶點擊切換SegmentButton 時,無回調, 回調需要獲取到點擊按鈕的index
參考以下demo:
import {ItemRestriction,SegmentButton,SegmentButtonItemTuple,SegmentButtonOptions,SegmentButtonTextItem
} from '@ohos.ArkUI.advanced.SegmentButton'@Entry
@Component
struct Index {@State tabOptions: SegmentButtonOptions = SegmentButtonOptions.tab({buttons: [{ text: '頁簽按鈕1' }, { text: '頁簽按鈕2' }, {text: '頁簽按鈕3'}] as ItemRestriction<SegmentButtonTextItem>,backgroundBlurStyle: BlurStyle.BACKGROUND_THICK})@State tf:boolean=true@State @Watch('onSegmentButtonChange') tabSelectedIndexes: number[] = [0]onSegmentButtonChange() {this.tf=!this.tfconsole.log(`選中按鈕索引 -- ${this.tabSelectedIndexes}`);}aboutToAppear(): void {console.log("122233")}build() {Row() {Column() {Column({ space: 25 }) {SegmentButton({ options: this.tabOptions,selectedIndexes: $tabSelectedIndexes })TextInput({text:`${this.tabSelectedIndexes}`}).enabled(this.tf)}.width('90%')}.width('100%')}.height('100%')}
}
3、HarmonyOS java PathMeasure 對應的api?
關于PathMeasure,HarmonyOS提供了Path路徑繪制組件,可以參考文檔:
https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-drawing-components-path-V5
關于transform,HarmonyOS提供了transform函數用于設置組件的變換矩陣:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-attributes-transformation-V5#transform
可以使用@ohos.graphics.drawing
模塊提供的接口來測量自定義路徑的長度。具體步驟如下:
導入@ohos.graphics.drawing
模塊: 確保在項目中導入了@ohos.graphics.drawing
模塊,以便使用其提供的繪圖和測量功能。- 創建Path對象: 使用Path對象來定義和繪制自定義路徑。
- 測量路徑長度: 使用
@ohos.graphics.drawing
模塊提供的接口來測量Path對象所表示的路徑的長度。具體接口如下:getLength(path: Path): number:返回路徑的長度。 - 示例步驟:創建一個Path對象,使用moveTo、lineTo和close方法構建路徑。調用getLength方法,傳入創建的Path對象,獲取路徑的長度。通過以上步驟,可以在HarmonyOS系統中實現對canvas路徑的測量。系統中實現對canvas路徑的測量。
4、HarmonyOS 如何在父組件中調用子組件的方法?
@Component
struct Child {@State private text: string = '初始值'private controller: ChildController = new ChildController();aboutToAppear() {if(this.controller) {//給controller對應的方法賦值this.controller.changeText = this.changeText}}//封裝的能力private changeText = (value: string) =>{this.text = value}build() {Column() {Text(this.text)}}
}//定義controller對象
class ChildController {changeText = (value: string) => {}
}@Entry
@Component
struct Parent {private ChildRef = new ChildController()build() {Column() {Text('調用Child的changeText').fontSize('18vp').fontColor(Color.Gray)Divider()Child({ controller:this. ChildRef })Button('Parent調用childer的changeText').onClick(() => {this.ChildRef.changeText('Parent調用childer的changeText')})}.justifyContent(FlexAlign.Center).width("100%").height("100%")}
}
5、HarmonyOS input的cancleButton無法對齊?
input的cancleButton無法對齊
目前textInput的cancelButton暫時不支持清除右邊距,可以使用row容器布局,并將justifyContent屬性設置為FlexAlign.SpaceBetween進行實現。
參考demo:
Row(){TextInput({ placeholder: '選填', text: '' }).placeholderColor("#99262626").textAlign(TextAlign.End).placeholderFont({ size: 14 }).fontColor(Color.Black).borderRadius(0).backgroundColor(Color.Transparent).fontSize(14).padding(0).onChange((value: string) => {this.inviteCode = value;}).width('95%')Image($r("app.media.app_icon")).height(20).onClick(() => {})
}.justifyContent(FlexAlign.SpaceBetween).width('100%')