【问题标题】:Layout is under StatusBar and Soft Keys布局在状态栏和软键下
【发布时间】:2015-08-20 21:12:22
【问题描述】:

我不确定我是如何得到这个的,也找不到类似的东西,但是我的软件导航和状态栏被绘制在我的布局上,而不是我的布局适合它们之间。

如何让我的布局在它们之间而不是在下方绘制?

编辑:

这似乎是罪魁祸首,位于样式中:

    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">true</item>

【问题讨论】:

  • 请提供更多细节或截图。我不明白你的问题...
  • 我添加了一张粗略的图片。对不起!哈。我没有意识到我终于获得了上传图片的权限。
  • 也许您的项目是从全屏活动开始的。请给我们一些代码,例如您的 AndroidManifest 中的 Activity 部分和您的 xml 布局。
  • 是的,请尝试提及一些代码,例如您的布局、styles.xml 和您的活动。

标签: android android-layout navigationbar translucency android-statusbar


【解决方案1】:

解决这个问题:

<item name="android:windowTranslucentStatus">false</item>
<item name="android:windowTranslucentNavigation">false</item>

或者干脆删除它们。这些属性使您的 StatusBar 和 NavigationBar 半透明,这就是为什么您的布局就像全屏一样。

【讨论】:

    【解决方案2】:

    使用它来获取到 RootView 的边距底部并且导航不重叠

    public static int getSoftButtonsBarSizePort(Activity activity) {
    // getRealMetrics is only available with API 17 and +
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        DisplayMetrics metrics = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
        int usableHeight = metrics.heightPixels;
        activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
        int realHeight = metrics.heightPixels;
        if (realHeight > usableHeight)
            return realHeight - usableHeight;
        else
            return 0;
    }
    return 0;
    }
    

    还有 OnCreate 方法

    var rootView = ((ViewGroup)this.FindViewById(Android.Resource.Id.Content)).GetChildAt(0);
            //var rootView = this.Window.DecorView.RootView;
    
            ViewGroup.MarginLayoutParams layoutParams;
    
            if (rootView.LayoutParameters != null)
            {
                layoutParams = (ViewGroup.MarginLayoutParams)rootView.LayoutParameters;
    
            }
            else
            {
                layoutParams = new ViewGroup.MarginLayoutParams(rootView.Width, rootView.Height);
            }
    
    
            var margin = GetSoftButtonsBarSizePort(this);
    
            layoutParams.SetMargins(rootView.Left, rootView.Top, rootView.Right, margin);
            rootView.LayoutParameters = layoutParams;
            rootView.RequestLayout();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      • 2016-10-14
      • 2015-06-06
      • 1970-01-01
      • 2013-06-21
      相关资源
      最近更新 更多