Search code examples
javaandroidhuawei-mobile-serviceshuawei-developersharmonyos

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


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.


Solution

  • Please check height and width of custom component is properly set.

    Or you can assign values when instantiating popup dialog like -

    PopupDialog popupDialog = new PopupDialog(getContext(), associated, width, height);

    Also, you’ll need to set custom component to popup dialog before show like -

    popupDialog.setCustomComponent(component);

    Here is an example from the HarmonyOS developer website

    https://developer.harmonyos.com/en/docs/documentation/doc-guides/faq-java-developing-0000001073311795