MIUI顯示懸浮窗

來源:互聯網
上載者:User

標籤:

1. 使用懸浮框

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

2. 具體實現

package com.pandans.hnairexam;import com.pandans.sunshine.provider.SunShineDB.BookT;import android.app.Application;import android.content.Context;import android.graphics.PixelFormat;import android.util.DisplayMetrics;import android.view.Gravity;import android.view.WindowManager;import android.view.WindowManager.LayoutParams;public class ExamApplication extends Application {private WindowManager.LayoutParams windowParams = null;public WindowManager.LayoutParams getWindowParams() {if (windowParams == null) {createWindowParams();}return windowParams;}private WindowManager.LayoutParams createWindowParams() {windowParams = new WindowManager.LayoutParams();windowParams.type = WindowManager.LayoutParams.TYPE_PHONE;windowParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL| WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;windowParams.format = PixelFormat.TRANSLUCENT;/* * 注意,flag的值可以為: 下面的flags屬性的效果形同“鎖定”。 懸浮窗不可觸摸,不接受任何事件,同時不影響後面的事件響應。 * LayoutParams.FLAG_NOT_TOUCH_MODAL 不影響後面的事件 * LayoutParams.FLAG_NOT_FOCUSABLE 不可聚焦 LayoutParams.FLAG_NOT_TOUCHABLE * 不可觸摸 */// 調整懸浮視窗至左上方,便於調整座標windowParams.gravity = Gravity.LEFT | Gravity.TOP;// 以螢幕左上方為原點,設定x、y初始值windowParams.x = 0;windowParams.y = 0;setDisplay(windowParams);return windowParams;}/** * 拖動已變更位元置 *  * @param x * @param y */public void updateWindows(int x, int y) {windowParams.y = y;((WindowManager) getSystemService(WINDOW_SERVICE)).updateViewLayout(mFloatView, windowParams);}public void setDisplay(WindowManager.LayoutParams params) {DisplayMetrics dm = new DisplayMetrics();((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay().getMetrics(dm);params.width = LayoutParams.MATCH_PARENT;params.height = (int) (dm.heightPixels * 0.4);//params.height = 200;}private PFloatView mFloatView;public void createView(Context cnt) {if (mFloatView == null) {mFloatView = new PFloatView(cnt);mFloatView.setSpinnerData(cnt, getContentResolver().query(BookT.CONTENT_URI, null, null, null, null));((WindowManager) getSystemService(WINDOW_SERVICE)).addView(mFloatView, getWindowParams());}}public void clearView() {if (mFloatView != null) {((WindowManager) getSystemService(WINDOW_SERVICE)).removeView(mFloatView);mFloatView = null;}}}

  

實際使用過程中發現miui的機器無法彈出懸浮窗,經查證,小米有做個許可權,預設懸浮窗都不能彈出。

 

解決:

1、在案頭找到系統應用“資訊安全中心”
  
輕擊一下即進入了此應用
  

2、點擊右下角的“授權管理”進入
  

點擊第二項“應用許可權管理”就進入了詳細的管理介面
       

3、右滑進入許可權管理,在最下方找到懸浮窗選修,點擊進入

4. 點擊表徵圖勾選允許

 

 

MIUI顯示懸浮窗

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.