如何获取Ability的根容器ComponentContainer,就像android那样:getWindow().getDecorView();

如题

Ability
根布局
decorView
2021-07-08 17:37:56
浏览
1
收藏 0
回答 3
待解决
回答 3
按赞同
/
按时间
XFJingGG
2
1

1,用代码创建根布局

DirectionalLayout componentContainer = new DirectionalLayout(this);
super.setUIContent(componentContainer);

2,给根布局设置id,然后使用

Component component = getWindow().getLayoutScatter().parse(int xmlId, ComponentContainer root, boolean attachToRoot);

或许还有更好的方法,等大神来回复。

分享
微博
QQ
微信
回复
2021-07-09 09:42:19
没用的喵叔
1

参考一下:https://gitee.com/openharmony-tpc/XPopup/blob/master/library/src/main/java/com/lxj/xpopup/util/ComponentUtil.java

 

    /**
     * 获取根容器
     *
     * @param component 根容器中的任意一个控件
     * @return 根容器
     */
    public static ComponentContainer getDecorView(Component component) {
        if (component != null) {
            ComponentParent componentParent = component.getComponentParent();
            if (componentParent == null) {
                return (ComponentContainer) component;
            } else {
                return getDecorView((Component) componentParent);
            }
        } else {
            return null;
        }
    }
分享
微博
QQ
微信
回复
2021-08-19 20:30:07
Oisnull

我也想知道,怎么样获取可视区域的宽高,像android中的getWindow().getDecorView().getWindowVisibleDisplayFrame,不知道有人知道没?

分享
微博
QQ
微信
回复1
2021-08-19 16:14:17
相关问题
请问如何获取到鸿蒙布局
4837浏览 • 1回复 待解决
如何获取指定Bundle NameAbility信息
133浏览 • 1回复 待解决
getWindow().setBackground用法
3048浏览 • 1回复 待解决
openharmony上如何获取类似android_id
2590浏览 • 1回复 待解决
如何隐藏容器组件溢出内容
342浏览 • 1回复 待解决
请问如何去掉ability转场动画?
9336浏览 • 2回复 待解决
鸿蒙开发如何默认启动ability
6489浏览 • 3回复 待解决
如何容器定位到屏幕最底部
196浏览 • 1回复 待解决
如何阻止Flex容器鼠标事件穿透
182浏览 • 1回复 待解决
ArkTs如何自定义容器组件?
941浏览 • 1回复 待解决
如何AbilityUI界面设置成透明
206浏览 • 1回复 待解决