【问题标题】:android replace status bar and prevent access to existing status barandroid替换状态栏并阻止访问现有状态栏
【发布时间】:2014-07-07 08:58:26
【问题描述】:

我在这里阅读了几篇文章,但没有一篇是我正在寻找的。他们让我走了很长一段路,但我还有一个问题需要解决。

我正在使用适用于 Android 的 Xamarin,我目前的目标是 API 级别 14 及以上。

我有以下代码(C# 和 Xamarin)

IWindowManager windowManager;
WindowManagerLayoutParams parm = null;

View statusBarView = new View(this);

windowManager = GetSystemService(Context.WindowService).JavaCast<IWindowManager>();

statusBarView.SetBackgroundColor(Color.Green);

parm = new WindowManagerLayoutParams(WindowManagerLayoutParams.FillParent, 400,
                                     WindowManagerTypes.SystemOverlay, 
                                     WindowManagerFlags.LayoutNoLimits,
                                     Format.Transparent);

parm.Gravity = GravityFlags.Top;

windowManager.AddView(statusBarView, parm); 

注意:400只是我测试的一个数字,我会实际得到状态栏的实际高度。

这显示得很好,但用户仍然可以访问通知栏。有几个应用程序可以做我想做的事情,我只需要帮助解决最后一个难题。

那部分是如何防止触摸事件到达当前状态栏。

非常感谢所有帮助!

【问题讨论】:

    标签: c# android xamarin statusbar


    【解决方案1】:

    您想隐藏状态栏吗? 如果是,https://developer.android.com/training/system-ui/status.html

    【讨论】:

    • 这仍然允许用户访问默认的。我需要更换现有的。
    • 我不认为你可以在没有 root 的情况下删除他(如果我没记错的话,nova 需要 root 才能这样做)。
    【解决方案2】:

    如果你想禁用状态栏,使用这个

    protected override void OnCreate(Bundle bundle)
    
    {
    customViewGroup view = new customViewGroup(this);
    
                WindowManagerLayoutParams localLayoutParams = new WindowManagerLayoutParams();
                localLayoutParams.Type = WindowManagerTypes.SystemError;
                localLayoutParams.Gravity = GravityFlags.Top;
                localLayoutParams.Flags = WindowManagerFlags.NotFocusable |
                WindowManagerFlags.NotTouchModal | WindowManagerFlags.LayoutInScreen;
                localLayoutParams.Width = WindowManagerLayoutParams.MatchParent;
                localLayoutParams.Height = (int)(50 * Resources.DisplayMetrics.ScaledDensity);
                localLayoutParams.Format = Format.Transparent;
    
                manager.AddView(view, localLayoutParams);
    
    }
    
    
    public class customViewGroup : ViewGroup
            {
                public customViewGroup(Context context) : base(context)
                {
                }
                public override bool OnTouchEvent(MotionEvent ev)
                {
                    return true;
                }
                protected override void OnLayout(bool changed, int l, int t, int r, int b)
                {
                    // throw new NotImplementedException();
                }
            }
    

    为了再次启用

    manager.RemoveView(view);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-20
      • 2016-04-05
      • 2014-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多