android在activity内禁止状态栏菜单下拉
小白 2019-12-14 【原创文章】
禁止下拉菜单栏
需求:,禁止用户下拉状态栏。
温馨提示:如果有的地方变量报红,请用android studio 运行手续代码自动不全引用!
代码已写好如下:
package com.allmoeny; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.graphics.PixelFormat; import android.os.Build; import android.os.Bundle; import android.view.Gravity; import android.view.PixelCopy; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; import android.webkit.WebChromeClient; import com.facebook.react.ReactActivity; import java.lang.reflect.Method; public class MainActivity extends ReactActivity { /** * Returns the name of the main component registered from JavaScript. This is used to schedule * rendering of the component. */ @Override protected String getMainComponentName() { return "allmoeny"; } //方法一 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); prohibitDropDown(); } private void prohibitDropDown() { WindowManager 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); localLayoutParams.format = PixelFormat.TRANSPARENT;//CustomViewGroup //ViewGroup manager.addView(new customViewGroup(this), localLayoutParams); } }
中间的调用是我自己封装的
new customViewGroup(this)
具体代码如下:
package com.allmoeny; 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) { } //MotionEvent public boolean onInterceptTouchEvent(MotionEvent ev) { Log.v("customViewGroup", "**********Intercepted"); return true; } }
总结:自己辛苦搞了一天才研究出来的,
另一片文章是讲:平板禁用调底部菜单栏的:
来源:http://stackoverflow.com/questions/25284233/prevent-status-bar-for-appearing-android-modified
最新发布
- 守护进程-kill端口-输出日志-查看等!
- git 本地分支关联远程分支,合并!
- pytorch安装(含cuda、cudnn安装教程)!
- linux系统下ubuntu22.04安装Docker方法!
- 视频截取封面 =php-ffmpeg/php-ffmpeg!
- 常用实例2023-5-10!
- 富文本 塞入mysql 报错: General error: 1366 Incorrect string value: ‘\xF0\x9F\x98\x84‘ for column ‘content‘!
- 百度地图拖拽获取地址实例!
- php使用smtp鉴权方式发送邮件 插件PHPMailer!
- 有道翻译接口对接!