Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了View.OnSystemUiVisibilityChangeListener在Android服务中不起作用大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想知道是否要显示systemUI和Listenering.该窗口在service中创建

package com.example.testwindow;


import android.app.service;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.os.IBinder;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;

import com.android.internal.policy.Policymanager;

public class WindowManagerservice extends service {

    private String TAG ="WindowManagerservice";
    private Context mContext;
    private WindowManager mWindowManager;
    private Window mWindow;

    @Override
    public void onCreate() {
        super.onCreate();
        Log.i(tag,"oncreate view");
        this.mWindowManager = ((WindowManager) getSystemservice("window"));

        mContext = this;
    }

    @Override
    public int onStartCommand(Intent intent,int flags,int startId) {
        int i = super.onStartCommand(intent,flags,startId);
        View editWindow = LayoutInflater.from(mContext).inflate(R.layout.activity_main,null);
        mWindow = addWindow(editWindow,LayoutParams.TYPE_PHONE);

        int msystemUIVisibility = mWindow.getDecorView().getsystemUIVisibility();
        mWindow.getDecorView().setOnsystemUIVisibilitychangelistener(new  View.onsystemUIVisibilitychangelistener(){

            @Override
            public void onsystemUIVisibilityChange(int visibility) {
                Log.e(tag,"systemUI onsystemUIVisibilityChange ="+visibility);
            }

        });
        Log.e(tag,"msystemUIVisibility ="+msystemUIVisibility);

        WindowManager.LayoutParams layoutParams = mWindow.getAttributes();
        layoutParams.x = 0;
        layoutParams.y = 0;
        layoutParams.width = 500;
        layoutParams.height = 600;
        layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
        layoutParams.hassystemUIListeners = true;
        layoutParams.settitle("WindowManagerservice");
        mWindow.setAttributes(layoutParams);
        mWindowManager.updateViewLayout(mWindow.getDecorView(),layoutParams);
        return i;
    }


    public WindowManager.LayoutParams createLayoutParams() {
        Log.i(tag,"createLayoutParams");
        WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
                 LayoutParams.TYPE_SYstem_ERROR,LayoutParams.FLAG_NOT_FOCUSABLE,PixelFormat.TRANSLUCENT);
        layoutParams.sofTinputMode = LayoutParams.soFT_INPUT_ADJUST_PAN;
        layoutParams.settitle(getClass().getName());
        return layoutParams;
    }

    public Window addWindow(View paramView,int width,int height,int typE) {
        Log.i(tag,"addWindow view");
        WindowManager.LayoutParams layoutParams = createLayoutParams();     
        Window localWindow = Policymanager.makeNewWindow(this.mContext);
        if (localWindow != null) {
            localWindow.setWindowManager(this.mWindowManager,null,null);
            localWindow.requestFeature(Window.FEATURE_NO_titlE);
            localWindow.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
            layoutParams.width = width;
            layoutParams.height = height;
            layoutParams.type = type;
            layoutParams.format= PixelFormat.TRANSPARENT;
            layoutParams.flags = (LayoutParams.FLAG_NOT_FOCUSABLE | layoutParams.flags);
            localWindow.setAttributes(layoutParams);
            localWindow.setContentView(paramView);
            View localView = localWindow.getDecorView();
            if (localView != null) {
                localView.setVisibility(View.VISIBLE);
                this.mWindowManager.addView(localView,layoutParams);
            }
            return localWindow;
        }   
        return null;
    }


    @Override
    public IBinder onBind(Intent intent) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void onDestroy() {
        if (mWindow != null) {
            mWindowManager.removeView(mWindow.getDecorView());
            mWindow = null;
        }
        super.onDestroy();
    }
}

当我开始服务时,其他应用程序更改为FULLSCREEN,我无获取日志“systemUI onsystemUIVisibilityChange =”

有人可以解释这种行为吗?为什么听不到改变?

解决方法

您可以在调用addView之前尝试添加侦听器.

大佬总结

以上是大佬教程为你收集整理的View.OnSystemUiVisibilityChangeListener在Android服务中不起作用全部内容,希望文章能够帮你解决View.OnSystemUiVisibilityChangeListener在Android服务中不起作用所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。