润和DAYU200(RK3568)
OpenHarmony4.1Release
屏幕属性提供管理显示设备的一些基础能力,包括获取默认显示设备的信息,获取所有显示设备的信息以及监听显示设备的插拔行为。早上有人在群里问,于是给回复一下,
import { BusinessError } from '@ohos.base';
import display from '@ohos.display';
@Entry
@Component
struct DisplayPage {
@State message: string = '坚果派';
build() {
RelativeContainer() {
Text(this.message)
.id('HelloWorld')
.fontSize(50)
.fontWeight(FontWeight.Bold)
.alignRules({
center: { anchor: '__container__', align: VerticalAlign.Center },
middle: { anchor: '__container__', align: HorizontalAlign.Center }
})
.onClick(() => {
let displayClass: Array<display.Display> = [];
display.getAllDisplays((err: BusinessError, data: Array<display.Display>) => {
displayClass = data;
const errCode: number = err.code;
if (errCode) {
console.error('Failed to obtain all the display objects. Code: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in obtaining all the display objects. Data: ' + JSON.stringify(data));
this.message=JSON.stringify(data[0].densityDPI)
});
})
}
.height('100%')
.width('100%')
}
}
https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkui/js-apis-display.md