直播app开发,推出语音聊天室时保持悬浮窗存在状态

直播app开发,推出语音聊天室时保持悬浮窗存在状态实现的相关代码

 

    private WindowManager mWindowManager;
    private WindowManager.LayoutParams wmParams;
    private LinearLayout mFloatInfoView;//悬浮窗布局文件
    private TextView mTvInfoMessage;
MainActivity()
{
if(windowOn == true)
{
showTheWindows();
}else
{
if (mWindowManager != null &&mFloatInfoView != null ) {
                mWindowManager.removeViewImmediate(mFloatInfoView);
                    }
}
}
public void showTheWindows()
    {
 
        Context appContext = context.getApplicationContext();
        // 获取WindowManager
        mWindowManager = (WindowManager) appContext.getSystemService(Context.WINDOW_SERVICE);
        mFloatInfoView = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.float_test_info_view, null);
        initMoveableParams();
        initInfoWindow();
    }
public void initMoveableParams() {
        wmParams = new WindowManager.LayoutParams();
        wmParams.type = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ?
                WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY :
                WindowManager.LayoutParams.TYPE_PHONE;
        wmParams.format = PixelFormat.RGBA_8888;
        wmParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
        wmParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
        wmParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
        wmParams.gravity = Gravity.RIGHT | Gravity.BOTTOM;
    }
   public boolean initInfoWindow() {
    boolean b = false;
        //get layout
        LayoutInflater inflater = LayoutInflater.from(context);
        if (inflater == null) {
        log("[initInfoWindow] inflater = null");
            return b;
        }
        mFloatInfoView = (LinearLayout) LayoutInflater.from(context).inflate(com.mediatek.internal.R.layout.float_test_info_view, null);
        if (mFloatInfoView == null) {
        log("[initInfoWindow] mFloatInfoView = null");
            return b;
        }
        mWindowManager.addView(mFloatInfoView, wmParams);
        return true;
    }

以上就是 直播app开发,推出语音聊天室时保持悬浮窗存在状态实现的相关代码,更多内容欢迎关注之后的文章

 

posted @ 2022-01-13 14:19  云豹科技-苏凌霄  阅读(61)  评论(0编辑  收藏  举报