Search code examples
androidnavigation-drawerstatusbarmaterial-design

Navigation Drawer not occure on Status Bar


Actually i am trying to do navigation drawer but i want it on status bar not below it i put all kind of code to make it transparent but still don't work My xml layout is like

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:elevation="7dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/tool_bar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/actionbar_color"
            app:contentInsetEnd="0dp"
            app:contentInsetStart="0dp"></android.support.v7.widget.Toolbar>

        <FrameLayout
            android:id="@+id/content_fragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/drawer_Linearlayout"
        android:layout_width="260dp"
        android:layout_gravity="start|top"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="168dp"
            android:scaleType="fitXY"
            android:src="@drawable/navigation_img"
            android:id="@+id/mytext"/>

        <ListView
            android:id="@+id/navdrawer"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingLeft="5dp"
            android:layout_below="@+id/mytext"
            android:layout_gravity="start|bottom"
            android:background="#FFFFFF"
            android:choiceMode="singleChoice"
            android:divider="@android:color/transparent"
            android:dividerHeight="0dp"
            android:listSelector="@drawable/list_selector"
            android:paddingTop="5dp"></ListView>

</LinearLayout>
</android.support.v4.widget.DrawerLayout>

My Theme is for v-21

<style name="AppThemes" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="android:windowTranslucentStatus">true</item>
        <item name="windowActionModeOverlay">true</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
        <item name="colorPrimary">@color/actionbar_color</item>
        <item name="colorPrimaryDark">@color/alert_normal</item>
        <item name="colorAccent">@color/actionbar_color</item>
        <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
    </style>

When i remove LinearLayout and ImageView it work fine but i want imageview inside DrawerLayout but actually it supports only 2 child elements so i have to use LinearLayout Please suggest me way to do that way.


Solution

  • I got solution for such layout. Sorry for posting late. I just have to make a little change in xml just like that.

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:elevation="7dp">
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
        <include layout="@layout/app_bar"></include>
    
        <FrameLayout
            android:id="@+id/content_fragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    
    </LinearLayout>
    
    <LinearLayout
        android:id="@+id/drawer_Linearlayout"
        android:layout_width="260dp"
        android:layout_gravity="left|start"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="168dp"
            android:scaleType="fitXY"
            android:src="@drawable/navigation_img"
            android:id="@+id/mytext" />
    
        <ListView
            android:id="@+id/navdrawer"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingLeft="5dp"
            android:layout_below="@+id/mytext"
            android:layout_gravity="start|bottom"
            android:background="#FFFFFF"
            android:choiceMode="singleChoice"
            android:divider="@android:color/transparent"
            android:dividerHeight="0dp"
            android:listSelector="@drawable/list_selector"
            android:paddingTop="5dp"></ListView>
    
    </LinearLayout>
    </android.support.v4.widget.DrawerLayout>
     

    And also make your theme style for v-21 like that.

    <!-- Base application theme. -->
        <style name="AppThemes" parent="Theme.AppCompat.Light.NoActionBar">
            <!-- Customize your theme here. -->
            <item name="android:windowTranslucentStatus">true</item>
            <item name="colorPrimary">@color/actionbar_color</item>
            <item name="android:textColor">@color/myNavigationColor</item>
            <item name="android:statusBarColor">@android:color/transparent</item>
            <item name="titleTextStyle">@style/ActionBarTitleText</item>
            <item name="colorPrimaryDark">@color/actionbar_primary_color</item>
            <item name="colorAccent">@color/actionbar_color</item>
            <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
            <item name="android:actionOverflowButtonStyle">@style/MyActionButtonOverflow</item>
        </style>

    and normal theme style is like

    <style name="AppThemes" parent="Theme.AppCompat.Light.NoActionBar">
            <!-- Customize your theme here. -->
            <item name="colorPrimaryDark">@color/actionbar_primary_color</item>
            <item name="colorPrimary">@color/actionbar_color</item>
            <item name="windowActionModeOverlay">true</item>
            <item name="android:textColor">@color/myNavigationColor</item>
            <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
            <item name="android:actionOverflowButtonStyle">@style/MyActionButtonOverflow</item>
        </style>

    Hope if you get stuck in such situation, these will be the solution for you.