Tuesday, 15 November 2016

Android: Toolbar not appearing on some devices (pre lollipop) using ActionDrawer (navigation drawer)


This is a common issue becoming less apparent when testing on Lollipop or later.
When using standard layouts (such as FrameLayoutRelativeLayout etc.) the default behavior is that child views get drawn in order they are added or inflated.
The fix would look similar to this:
<FrameLayout>
     <!-- Content will be drawn first - below the toolbar. -->
     <FrameLayout android:id="@+id/main_content" />
     <!-- Toolbar will be drawn next - above the content. -->
     <android.support.v7.widget.Toolbar android:id="@+id/toolbar" />
</FrameLayout>
However since Lollipop the android:elevation attribute can override this behavior. Since elevation defines precise position along the Z axis views with higher elevation values will be drawn above those with lower elevation values.

6 comments: