Get view of AccessibilityNodeInfo to create overlay

前端 未结 2 1215
我寻月下人不归
我寻月下人不归 2021-02-09 17:33

I\'m writing a AccessibilityService and I want to create view overlays on the views from the current activity that the accessibility service can retrieve. I have no

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-09 17:44

    Drawing overlays over the window using accessibility services is easy. I know this is an old question, but I thought I'd add the answer anyway.

    RelativeLayout relativeLayout = new RelativeLayout(getContext());
    
    WindowManager.LayoutParams topButtonParams = new WindowManager.LayoutParams(
        width, //The width of the screen
        height, //The height of the screen
        WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
        PixelFormat.TRANSLUCENT);
    
    //Just trust me, this alpha thing is important.  I know it's weird on a "translucent" view.
    topButtonParams.alpha = 100;
    
    relativeLayout.setLayoutParams(topButtonParams);
    
    mWindowManager.addView(relativeLayout, topButtonParams);
    

    Also, you need this permission in your manifest

    
    

    Once you have an invisible relative layout overlay over the top of the entire screen, adding views to it is easy!

提交回复
热议问题