Android 為應用增加可移動的懸浮視窗
需求描述:
在使用手機客戶端瀏覽內嵌網頁的時候,介面出現一個懸浮的重新整理按鈕,點選網頁重新載入。
佈局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/float_fresh"
android:padding="5dp"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/icon_fresh"
android:background="@drawable/bg_floatbutton"/>
</LinearLayout>
設定視窗型別在所有視窗之上:
這裡說一下這個LayoutParams.TYPE_PHONE。我們看一下官方文件說明:
These are non-application windows providing user interaction with the phone (in particular incoming calls). These windows are normally placed above all applications, but behind the status bar. In multiuser systems shows on all users' windows.
就是說設定了這個屬性之後,這個視窗會在所以的介面之上,但是在狀態列的下面。在多使用者系統中,所有使用者的視窗上都會顯示。
定義拖動和點選事件:
mFloatView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
wmParams.x = sWidth - (int) event.getRawX() - mFloatLayout.getMeasuredWidth() / 2;
wmParams.y = sHeight - (int) event.getRawY() - mFloatLayout.getMeasuredHeight() / 2;
if(wmParams.y > sHeight - titleHeight){
return true;
}
//重新整理
mWindowManager.updateViewLayout(mFloatLayout, wmParams);
return false;
}
});
mFloatView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
web.reload();
}
});
別忘了許可權宣告:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />效果圖:
相關文章
- 懸浮窗的一種實現 | Android懸浮窗Window應用Android
- Android 懸浮視窗的實現Android
- Android應用內懸浮窗的實現方案Android
- Android 懸浮窗Android
- Android 輔助許可權與懸浮窗Android
- 短視訊app原始碼,連麥時最小化出現可移動懸浮窗APP原始碼
- Android懸浮窗的學習Android
- 浮動應用程式視窗怎麼用?
- 非侵入式無許可權應用內懸浮窗的實現
- 下沉式通知的一種實現 | Android懸浮窗Window應用Android
- 固定位置的Js懸浮視窗JS
- Android 懸浮窗 System Alert WindowAndroid
- 直播軟體原始碼,設定懸浮窗並可進行任意位置的移動原始碼
- 短視訊系統原始碼,關於懸浮窗的縮放、拖動等應用原始碼
- Android 攝像頭預覽懸浮窗,可拖動,可顯示在其他app上方AndroidAPP
- HTML 滑鼠放上顯示懸浮視窗HTML
- Android 攝像頭預覽懸浮窗Android
- Android仿微信文章懸浮窗效果Android
- Android懸浮窗--獲取記憶體Android記憶體
- Andorid 任意介面懸浮窗,實現懸浮窗如此簡單
- Android 懸浮窗許可權各機型各系統適配大全Android
- 【轉載】使用WindowManage實現Android懸浮窗Android
- 如何獲取Vivo系統的懸浮窗許可權狀態
- 如何在macOS中透過應用程式視窗浮動註釋Mac
- 微信小程式懸浮可拖動客服元件微信小程式元件
- Android懸浮窗TYPE_TOAST小結: 原始碼分析AndroidAST原始碼
- 直播原始碼,懸浮窗滾動漸變色效果原始碼
- QPM 之懸浮窗設定資訊
- 適配懸浮窗許可權與系統設定修改許可權
- Android中的懸浮框Android
- 滑鼠懸浮元素上下滑動增加或者減少高度效果
- Android開發筆記(一百一十八)自定義懸浮窗Android筆記
- Android實現仿360手機衛士懸浮窗效果Android
- Fluid Browser for Mac(多工懸浮透明視窗瀏覽器)1.6啟用版UIMac瀏覽器
- Android桌面懸浮框Android
- QPM 之懸浮窗助力效能優化優化
- 懸浮窗開發設計實踐
- iOS自帶懸浮窗除錯工具iOS除錯