通过使用下面的代码,我可以通过全屏隐藏通知栏
android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen"
要么
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
但我想要做的是完全禁用状态栏.我正处于所谓的"自助服务终端模式",我想确保用户不能从顶部挡板上滑下手指.上述两种解决方案都可以隐藏通知栏,但它不适用于在应用程序中完全禁用它.
这可能吗?
而不是跟随其他答案的链接,这是我做的.
如果下拉(即使在全屏幕应用程序中),此解决方案也不允许用户"查看"处于"预览"状态的状态栏,但它不允许用户将状态栏拉到其完整状态以查看设置,通知等
您必须先在您的帐户中添加权限 AndroidManifest.xml
然后添加另一个被调用的类(Java文件)customViewGroup.java
并将此代码放入其中:
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) { Log.v("customViewGroup", "**********Intercepted"); return true; } }
完成这两项设置后,您可以将其添加到主体中 onCreate()
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 view = new customViewGroup(this); manager.addView(view, localLayoutParams);
此解决方案禁用始终向下拉状态栏的功能,直到您的应用关闭.如果您不想每次都关闭应用,则必须在暂停时删除此操作.
从本回答中获得@Abhimaan Madhav的信用