ANDROID:如何在屏幕上创建一个虚拟区域,位于用户可以按下以执行操作的所有内容之上?

发布于 2024-12-02 16:37:42 字数 150 浏览 2 评论 0原文

我正在尝试对 swipepad、taskxp 和 taskie 等用户滑动的应用程序做一些类似的事情
或者触摸手机屏幕的某个区域(例如边缘),即使未显示程序的活动,程序也会运行。

我不知道从哪里开始,因为我什至不知道它叫什么

任何帮助将不胜感激!

i am trying to do something silmiar to apps like swipepad, taskxp, and taskie where the user swipes
or touches an area of the phone screen like the edges and the program functions even if its activity is not shown.

I have no idea where to start since i dont even know whats its called

Any help would be much appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

原来是傀儡 2024-12-09 16:37:42

这是类似问题的答案 获取坐标触摸屏后台服务

不,抱歉。您的活动可以将有关触摸事件的信息传递给
一个服务,但服务不能直接接收触摸事件

,但只能在活动运行时接收触摸事件。

以下是在活动中创建触摸侦听器的方法:

ImageView playLayout = (ImageView)findViewById(R.id.playLayout);
    playLayout.setKeepScreenOn(true);

    playLayout.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent me) {
            float newY = me.getY();
            float newX = me.getX();
            int action = me.getAction();

            if (action==0){
                Log.v(tag, "New Touch");
                Log.i(tag, String.valueOf("Action " + action +
                        " happened at X,Y: " + "("+newX+","+newY + ")"));
            }
            return true;
        }
    });     

当然,您可以向其中添加更多内容。在那里,我只是记录触摸发生位置的 x 和 y 坐标。

Here's the answer to a similar question Get co-ordinates touch screen in a background service:

No, sorry. Your activities can pass information about touch events to
a service, but a service cannot directly receive touch events

But you can only receive touch events with an activity running.

Here's how you would do a touch listener in an activity:

ImageView playLayout = (ImageView)findViewById(R.id.playLayout);
    playLayout.setKeepScreenOn(true);

    playLayout.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent me) {
            float newY = me.getY();
            float newX = me.getX();
            int action = me.getAction();

            if (action==0){
                Log.v(tag, "New Touch");
                Log.i(tag, String.valueOf("Action " + action +
                        " happened at X,Y: " + "("+newX+","+newY + ")"));
            }
            return true;
        }
    });     

Of course you can add more to it. There, I'm just logging the x and y coordinates of where the touch happened.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文