美文网首页
WindowManager展示window的限制

WindowManager展示window的限制

作者: xbase | 来源:发表于2017-08-10 16:10 被阅读19次

在android7.1系统上,为了防止一个应用的悬浮窗一直悬浮在另一个应用上造成干扰,故使用TYPE_SYSTEM_ALERT。

WindowManager.LayoutParams params = new WindowManager.LayoutParams();
        if(Build.VERSION.SDK_INT >= 25){
            params.type = params.TYPE_SYSTEM_ALERT;
        }else if(Build.VERSION.SDK_INT >= 19) {
            params.type = params.TYPE_TOAST;
        }else {
            params.type = params.TYPE_PHONE;
        }

而且android系统限制同一时间只能有一个弹窗存在,否则抛出异常。

有一个问题,到现在没想清楚,如下:

params.windowAnimations = R.style.new_order_anim;

看一眼源代码,其中有这样一段注释:

 A style resource defining the animations to use for this window. 
This must be a system resource; 
it can not be an application resource 
because the window manager does not have access to applications.

大意为windowManager中的这个windowAnimations只能接受系统资源style,不能接受appllication中的资源文件,原因是没有权限,but,经过真机与模拟器的验证,竟然可以正常展示进出动画,查询很多资料至今无解。

<style name="anim">
        <item name="android:windowEnterAnimation">@anim/translate_top_to_bottom</item>
        <item name="android:windowExitAnimation">@anim/translate_bttom_to_top</item>
    </style>

translate_top_to_bottom

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:fromXDelta="0%"
        android:toXDelta="0%"
        android:fromYDelta="-100%"
        android:toYDelta="0%"
        android:duration="800"/>
</set>

translate_bttom_to_top

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:fromXDelta="0%"
        android:toXDelta="0%"
        android:fromYDelta="0%"
        android:toYDelta="-100%"
        android:duration="600"/>
</set>

相关文章

网友评论

      本文标题:WindowManager展示window的限制

      本文链接:https://www.haomeiwen.com/subject/oofwkxtx.html