在Android上叠加屏幕 [英] Overlay screen on Android

查看:272
本文介绍了在Android上叠加屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这怎么可能给浏览/图像添加到我的主屏幕?

How is it possible to add Views/Images to my homescreen?

最好的例子就是Facebook的使者:如果您长期在点击聊天的项目,你可以选择弹出金手指头,那么你有一个小按钮,覆盖你的屏幕

The best example is the facebook messenger: If you long-click at a chat item, you can choose "pop out cheat head", then you have a small button overlaying your screen.

还有一些应用程序,如屏式破碎机,来自一个破碎的显示图像覆盖了从手机。

There are also apps like screen-breakers, an image from a broken display overlays everything from the phone.

我搜索了它,但我不知道它叫什么。

I've searched for it, but I have no idea what it is called.

我希望你们能够理解我的英语水平。

I hope you guys are able to understand my english.

推荐答案

答案是SYSTEM_ALERT_WINDOW,这给你的能力吸引了在Android中,相同的功能Facebook的任何东西是用绘制其聊天头。

Answer is SYSTEM_ALERT_WINDOW, this give you capability to draw over any thing in android, same feature facebook is using for drawing its chat heads.

<一个href="http://developer.android.com/reference/android/Manifest.permission.html#SYSTEM_ALERT_WINDOW">http://developer.android.com/reference/android/Manifest.permission.html#SYSTEM_ALERT_WINDOW

样品code:

    private WindowManager windowManager;
    private ImageView imageView;
   // Get window manager reference

    windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

    imageView= new ImageView(YOUR_CONTEXT_HERE);
    imageView.setImageResource(R.drawable.android_head);

    // Setup layout parameter
    WindowManager.LayoutParams params = new WindowManager.LayoutParams(
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.TYPE_PHONE,
        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
        PixelFormat.TRANSLUCENT);

    params.gravity = Gravity.TOP | Gravity.LEFT; // Orientation
    params.x = 100; // where you want to draw this, coordinates
    params.y = 100;
    // At it to window manager for display, it will be printed over any thing
    windowManager.addView(chatHead, params);


   // Make sure to remove it when you are done, else it will stick there until you reboot
   // Do keep track of same reference of view you added, don't mess with that
   windowManager.removeView(imageView);

这篇关于在Android上叠加屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆