applibgroup / HarmonyOS-Knowledgebase

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

Why creating Popup dialog with custom component passed in constructor showing blank Dialog when .show() is called? #54

Closed alpesh12345 closed 3 years ago

alpesh12345 commented 3 years ago

Describe the query

I am developing a Harmony application where I want to create a popup dialog with a custom component. I tried this

Component customComponent = LayoutScatter.getInstance(context)
                .parse(ResourceTable.Layout_custom_dialog, null, false);
// I have already made custom component
PopupDialog popupDialog = new PopupDialog(getContext, customComponent);
popupDialog.show();

After running this I only see a White background Box and Custom Component is not visible. Why new PopupDialog(getContext, customComponent); is not setting customComponent.

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

**** https://stackoverflow.com/questions/68592453/why-creating-popup-dialog-with-custom-component-passed-in-constructor-showing-bl

Additional information

Developer Platform: Windows DevEco Studio version:2.1.0.501 SDK API version: 5 SDK version: 2.1.1.21 Device: Not required Device OS version: Not required

samuel-abhishek commented 3 years ago
new PopupDialog(getContext, customComponent);

The above constructor call will only acquire the height and width of customComponent that is passed in the constructor.

To customize the content of the popup dialog, you need to use the following API

public PopupDialog setCustomComponent​(Component customComponent)

You may refer this documentation for additional information