搭建直播平台,Android开发之禁止下拉通知栏的方法
思路:在状态栏上覆盖一层透明view,点击时,直接消费掉,禁止继续往下传递,接触不到状态栏,就拉不出来,比较笨的一个办法,但是也挺有效
废话说的不少了,上代码把:
//禁止下拉
private void UnDropDown() {
manager = ((WindowManager) getApplicationContext()
.getSystemService(Context.WINDOW_SERVICE));
WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams();
localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
localLayoutParams.gravity = Gravity.TOP;
localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
// this is to enable the notification to recieve touch events
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
// Draws over status bar
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
localLayoutParams.height = (int) (50 * getResources()
.getDisplayMetrics().scaledDensity); //50高度这边我是固定死了,也可以动态获取状态栏高度,然后赋值
localLayoutParams.format = PixelFormat.TRANSPARENT;
view = new CustomViewGroup(this);
manager.addView(view, localLayoutParams);
}
CustomViewGroup 代码:
import android.content.Context;
import android.util.Log;
import android.view.MotionEvent;
import android.view.ViewGroup;
public class CustomViewGroup extends ViewGroup {
public CustomViewGroup(Context context) {
super(context);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
//直接消费,不向下传递
return true;
}
}
不要忘记销毁
@Override
protected void onDestroy() {
super.onDestroy();
if (view != null) {
WindowManager manager = ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE));
manager.removeView(view);
}
}
以上就是 搭建直播平台,Android开发之禁止下拉通知栏的方法,更多内容欢迎关注之后的文章
标签:LayoutParams,WindowManager,int,直播,import,Android,搭建,localLayoutParams,view From: https://www.cnblogs.com/yunbaomengnan/p/17043591.html