在Android 4中覆盖导航栏

时间:2014-08-18 19:18:13

标签: android navigation overlay

尽管经历了一些样本,但我正在努力解决这个问题......

我想覆盖在android导航栏上 - 我尝试过以下代码......

s_translucentParams = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
                WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                        | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
                        | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                        | WindowManager.LayoutParams.FLAG_FULLSCREEN
                ,
                PixelFormat.TRANSLUCENT);

但是,当然,这填补了一个不覆盖导航栏的窗口......在做了一些阅读之后,我尝试了以下内容(来自Draw bitmaps on top of the Navigation bar in Android)......

w = new android.view.WindowManager.LayoutParams(-1, -1,0,-navigationBarHeight(),    WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_FULLSCREEN
|WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
|WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
|WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR 
|WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, Pixel.Translucent);
f.addView(v, w);

但是,尽管我改变了窗口大小,但这并没有覆盖我...它只是不与导航栏重叠:(

我想做类似以下的事情......

https://play.google.com/store/apps/details?id=com.haxor&hl=en_GB

这不会显示在导航栏上方,而是显示在它下方(这对我的需求来说很好)

任何人都可以帮助我吗?谢谢。

1 个答案:

答案 0 :(得分:0)

您在Play Market链接屏幕截图中看到的是Android KitKat(API 19)半透明装饰。

  

现在,您可以使用new来使系统条部分半透明   主题,Theme.Holo.NoActionBar.TranslucentDecor和   Theme.Holo.Light.NoActionBar.TranslucentDecor。通过启用半透明   系统栏,你的布局将填充系统栏后面的区域,所以   您还必须为布局的部分启用fitsSystemWindows   不应该由系统栏覆盖。

     

如果您要创建自定义主题,请将其中一个主题设置为   父主题或包含windowTranslucentNavigation和   

。主题中的windowTranslucentStatus样式属性。

您的半透明活动应在AndroidManifest.xml中声明:

<activity android:name="com.example.app.TranslucentActivity"
          android:theme="@android:style/Theme.Holo.NoActionBar.TranslucentDecor" />

您可能想要的其他方式只是隐藏带有API 14 +的导航栏:

View decorView = getWindow().getDecorView();
// Hide both the navigation bar and the status bar.
// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
// a general rule, you should design your app to hide the status bar whenever you
// hide the navigation bar.
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
              | View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);

或者您可能希望使用带有API 19的沉浸式全屏模式:

@Override
public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        decorView.setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);}
}

请查看Using Immersive Full-Screen ModeHiding the Navigation Bar以获取更多详细信息。