2014-01-18 28 views
3

在Android 4.4半透明狀態欄,在列表視圖NavigationDrawer重疊動作條略有下降。它可以在我測試過的所有其他API級別上正常工作。NavigationDrawer保證金使用與ActionBarCompat和NavigationDrawer半透明狀態欄選項時

據我所知,這是因爲marginTop選項從屏幕的頂部開始,而不是從操作欄的頂部(狀態欄的底部)開始。 狀態欄底部。有一個偏移

是否有解決方法嗎?我正在使用示例佈局,並將marginTop設置爲?attr/actionBarSize

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/layout_drawer" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <!-- As the main content view, the view below consumes the entire 
    space available using match_parent in both dimensions. --> 
    <FrameLayout 
     android:id="@+id/content_frame" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <!-- android:layout_gravity="start" tells DrawerLayout to treat 
    this as a sliding drawer on the left side for left-to-right 
    languages and on the right side for right-to-left languages. 
    The drawer is given a fixed width in dp and extends the full height of 
    the container. A solid background is used for contrast 
    with the content view. --> 
    <ListView 
     android:id="@+id/drawer_list" 
     android:layout_width="240dp" 
     android:layout_height="match_parent" 
     android:layout_marginTop="?attr/actionBarSize" 
     android:layout_gravity="start" 
     android:fitsSystemWindows="true" 
     android:choiceMode="singleChoice" 
     android:divider="@android:color/transparent" 
     android:dividerHeight="0dp" 
     android:background="@drawable/bg_app" /> 
</android.support.v4.widget.DrawerLayout> 
+0

你找到任何解決方案? – kalehv

回答

2

按照這裏的代碼 - https://github.com/afollestad/kitkat-transparency-demo

這可以讓你設置半透明狀態和導航欄,與NavigationDrawer一起。

覆蓋的onViewCreated在NavigationDrawer如下 -

@Override 
    public void onViewCreated(View view, Bundle savedInstanceState) { 
    super.onViewCreated(view, savedInstanceState); 

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return; 
    SystemBarTintManager tintManager = new SystemBarTintManager(getActivity()); 
    SystemBarTintManager.SystemBarConfig config = tintManager.getConfig(); 
    view.setPadding(0, config.getPixelInsetTop(true), config.getPixelInsetRight(), config.getPixelInsetBottom()); 
    } 

這是假設你正在使用SystemBarTint libary

https://github.com/jgilfelt/SystemBarTint

0

最後,我必須找到狀態欄高度並手動設置邊距。

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 
    DrawerLayout.LayoutParams lp = (DrawerLayout.LayoutParams) mDrawerList.getLayoutParams(); 
    lp.setMargins(0, lp.topMargin + getStatusBarHeight(), 0, 0); 
    mDrawerList.setLayoutParams(lp); 
} 

public int getStatusBarHeight() { 
    int result = 0; 
    int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); 
    if (resourceId > 0) { 
    result = getResources().getDimensionPixelSize(resourceId); 
    } 
    return result; 
} 
+0

爲什麼?我並不需要這樣做,但是我的狀態和導航欄都是半透明的,隨着NavigationDrawer的設置,它在List欄下方設置了List。在這裏查看屏幕截圖 - http://bit.ly/1nFHBD9和http://bit.ly/1nFHCak – kalehv

+1

該實現的唯一好處是避免了依賴關係。如果你打算使用這個庫,那麼這個庫更有意義。我最初使用這種方法,但不想在那裏的圖書館,因爲我沒有真正使用它。 –

+0

Gotcha。說得通。謝謝 – kalehv

相關問題