2015-01-27 45 views
0

在我的應用程序中,我將這些標誌用於全屏視頻。在用戶交互中,我顯示導航/狀態/工具欄。我正在使用帶工具欄的新API 21 AppCompat。遷移到api 21工具欄後,我的全屏活動狀態欄已經覆蓋了我的工具欄

這些都是顯示欄時,我使用的標誌:

mDecorView.setSystemUiVisibility(newVis); 

它遷移到L工具欄前的工作:

int newVis = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE 

然後調用。據推測,現在工具欄部分被狀態欄覆蓋,因爲它是活動佈局的一部分。我想我可以將工具欄向下移動一個等於狀態欄高度的靜態數量,但感覺這是一種黑客行爲。有沒有一個正確的方法來完成這個?

我的應用程序支持android 4.1+。就像我說的,在我開始使用工具欄之前,這並沒有發生,但它確實發生在android 4.1 - 5.0上。

回答

2

最後,修復包括做一些測量來確定操作欄和導航欄的大小。由於在橫向手機尺寸的設備上,軟導航欄最終顯示在顯示器的右側,並且還遮蓋了工具欄。下面的修復應該至少在android api-16到api-21上工作。代碼的後半部分只是爲了重置工具欄的裝飾,出於某種原因,操作欄中的代碼圖標最終沒有正確對齊(它們更靠近頂部)。希望這有助於其他人。

// Get the root activity layout id 
      RelativeLayout root = (RelativeLayout) findViewById(R.id.container); 
      root.post(new Runnable() 
      { 
       public void run() 
       { 
        Point size = new Point(); 
        Display display = getWindowManager().getDefaultDisplay(); 
        if (Integer.valueOf(android.os.Build.VERSION.SDK) >= Build.VERSION_CODES.JELLY_BEAN_MR1) 
        { 
         // This is only available on api 17 and higher 
         display.getRealSize(size); 
        } 
        else 
        { 
         // On api 16 and less this should work 
         display.getSize(size); 
        } 

        int screenWidth = size.x; 

        Rect rect = new Rect(); 
        Window win = getWindow(); // Get the Window 
        win.getDecorView().getWindowVisibleDisplayFrame(rect); 
        // Get the height of Status Bar 
        int statusBarHeight = rect.top; 
        int navBarWidth = screenWidth - rect.width(); 

        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mToolbar.getLayoutParams(); 

        android.util.TypedValue value = new android.util.TypedValue(); 
        getTheme().resolveAttribute(android.R.attr.actionBarSize, value, true); 
        TypedValue.coerceToString(value.type, value.data); 
        android.util.DisplayMetrics metrics = new android.util.DisplayMetrics(); 
        getWindowManager().getDefaultDisplay().getMetrics(metrics); 
        params.height = (int) value.getDimension(metrics); 

        params.setMargins(0, statusBarHeight, navBarWidth, 0); 
        mToolbar.setLayoutParams(params); 
       } 
      }); 

此外root.post(Runnable ...)部分是因爲我們無法測量窗口,直到oncreate完成。

0

我解決了它添加一個framelayout(height @ dimen/statusbarheight)。然後你可以設置每個版本和模式的高度。

一些例子:attrs.xml:

<dimen name="statusbarheight">0dp</dimen> 

attrs.xml V21:

<dimen name="statusbarheight">25dp</dimen> 

attrs.xml V21土地:

<dimen name="statusbarheight">0dp</dimen> 

當我裏面設置半透明導航欄風格我得到了同樣的問題。

+0

這不起作用。 25dp不夠高。另外我不確定所有設備的高度是否相同。或者是? – startoftext 2015-01-27 00:45:09

+0

標準高度是24dp,但我擔心這可以通過一些主題應用程序進行更改。 – 2015-01-27 01:36:32

+0

我試了nexus 5中的應用程序,nexus one和25 dp修復了我的問題。像谷歌衡量指標24 dp說對我來說是錯誤的。 – Dahnark 2015-01-27 01:39:00