如何在其他应用程序上方显示代码绘制的线条?

编程入门 行业动态 更新时间:2024-10-04 23:30:58
本文介绍了如何在其他应用程序上方显示代码绘制的线条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

详细信息:我想添加一条代码绘制的线(就像您使用画布/绘画进行绘制一样),并将其显示在其他应用程序上.

Details: I would like to add a code drawn line (like you draw with canvas/paint) and display it over other applications.

我目前有一个应用程序,可以让我在其他应用程序上显示图像.有关我的代码,请参见我的 Stackoverflow答案.我已经实现了这样做的权限:

I currently have an application that allows me to display an image over other application. See my Stackoverflow answer for my code. I have implemented the permission to do so:

android.permission.SYSTEM_ALERT_WINDOW

我尝试将画布/绘画添加到WindowManager中而没有错误,但是我的应用程序崩溃了.我曾尝试寻找答案,但已空了.

I have tried to add a canvas/paint to the WindowManager without errors, but my app crashed. I have tried searching for an answer, but have turned up empty.

如果有人可以帮助我解决这个问题,将不胜感激!

If anyone can help me figure this out, you will be greatly appreciated!

为了阐明这一点,我希望可以在可以在其他应用程序上使用它并且仍可以与其他应用程序进行交互的位置绘制此图.另外,我还添加了按钮功能,可以使用WindowManager addView和WindowManager removeView关闭/打开视图,但是每次添加视图时,它都覆盖了整个区域,因此我无法再单击按钮来删除视图./p>

To clarify: I would like this to be drawn where I can have it over other applications and where I can still interact with other applications. Also I've added a button functionality where I turn off/on a view with WindowManager addView and WindowManager removeView, but every time I add a view, it covers the entire area and I can no longer click the button to remove the view.

推荐答案

我找到了一种方法,将在此处分享.如果您需要更多代码,请使用指向我的> Stackoverflow答案我也链接了我的问题.

I have found a way and will share here. If you want more of the code, use the link to my Stackoverflow answer that I also linked in my question.

我想直到现在我都没有设置正确的代码,也没有租用所有的代码.

I guess I wasn't setting up the correct code, or at lease all of it, until now.

DrawView.java

package com.example.floatingicon; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.view.View; public class DrawView extends View{ Paint paint = new Paint(); public DrawView(Context context){ super(context); paint.setColor(Color.BLACK); } @Override public void onDraw(Canvas canvas){ canvas.drawLine(240, 0, 240, 620, paint); canvas.drawLine(0, 200, 480, 200, paint); } }

这将在屏幕上绘制一个十字形

This will draw a cross on the screen

MainService.java

import com.example.floatingicon.DrawView; public class MainService extends Service { private DrawView drawView; @Override public void onCreate() { drawView = new DrawView(this); final WindowManager.LayoutParams paramsDraw = new WindowManager.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, PixelFormat.TRANSLUCENT); paramsDraw.gravity = Gravity.TOP | Gravity.LEFT; paramsDraw.x=0; paramsDraw.y=0; winManager.addView(drawView, paramsDraw); } }

如果将其添加到已经存在的代码中,它应该可以正常工作.

If you add that to the already existing code, it should work just fine.

更多推荐

如何在其他应用程序上方显示代码绘制的线条?

本文发布于:2023-11-03 04:41:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1554261.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:线条   应用程序   代码   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!