在android7.1系統(tǒng)上槐臀,為了防止一個(gè)應(yīng)用的懸浮窗一直懸浮在另一個(gè)應(yīng)用上造成干擾,故使用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系統(tǒng)限制同一時(shí)間只能有一個(gè)彈窗存在,否則拋出異常瘾杭。
有一個(gè)問題站蝠,到現(xiàn)在沒想清楚汰具,如下:
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中的這個(gè)windowAnimations只能接受系統(tǒng)資源style菱魔,不能接受appllication中的資源文件留荔,原因是沒有權(quán)限,but澜倦,經(jīng)過真機(jī)與模擬器的驗(yàn)證聚蝶,竟然可以正常展示進(jìn)出動(dòng)畫,查詢很多資料至今無解。
<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>