applibgroup / HarmonyOS-Knowledgebase

This repository contains code samples of HarmonyOS Training
Apache License 2.0
17 stars 6 forks source link

What is the alternative in HarmonyOS for window.setDimAmount() in Android? #9

Closed sohamvg closed 3 years ago

sohamvg commented 3 years ago

Describe the query

To set the background dimness of a component like dialog box, in Android we can use the setDimAmount function.

dialog.getWindow().setDimAmount(0.5);

What is the alternative for this in HarmonyOS?

Create the query with harmonyos tag in stackoverflow and share the link here:

https://stackoverflow.com/questions/68540729/what-is-the-alternative-in-harmonyos-for-window-setdimamount-in-android

Additional information

Developer Platform: Windows DevEco Studio version: 2.1.0.303 SDK API version: 5 SDK version: 2.1.1.21 Device: Not Required Device OS version: Not Required

kanaksony commented 3 years ago

Just try to configure the attributes of the corresponding window after dialog.show().

dialog.show();
Optional<WindowManager.LayoutConfig> configOpt = dialog.getWindow().getLayoutConfig();
configOpt.ifPresent(config -> {
   config.dim = 0.0f;
   dialog.getWindow().setLayoutConfig(config);
});