Search code examples
androidnavigation-drawertoolbarslidedownhamburger-menu

I want to show menu, when I click burger menu on toolbar


I searched everywhere but don't got what I want'd.

Burger menu click on toolbar, must show menu, like navigation drawer menu, but not left side, I want it from top side. It must have slide down animation

here is two pictures, displaying what I want to achieve
before menu icon click :

before menu icon click

after click:

after click

this is my layout xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
     android:orientation="vertical"
     xmlns:android="http://schemas.android.com/apk/res/android"

     xmlns:tools="http://schemas.android.com/tools"

     android:layout_width="match_parent"
     android:layout_height="fill_parent"
     android:background="@color/white"
     android:id="@+id/container"
     android:focusableInTouchMode="true">


<!-- Toolbar -->
<include
    layout="@layout/toolbar"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"/>



<!-- main container layout -->
<LinearLayout
    android:fitsSystemWindows="true"
    android:background="@color/white"
    android:focusableInTouchMode="true"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    android:layout_weight="1"
    android:layout_width="match_parent"
    android:layout_height="0dp">



    <!-- content container layout-->
    <LinearLayout
        android:orientation="vertical"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp">

        <EditText
            android:id="@+id/player_one_id"
            android:hint="@string/hint_player_one"
            android:textSize="@dimen/player_name_text_size"
            android:imeOptions="actionDone"
            android:textColor="@color/text_color"
            android:textColorHint="@color/textColorHint"
            android:layout_width="match_parent"
            android:layout_weight="1"
            android:layout_height="0dp"/>



        <EditText
            android:id="@+id/player_two_id"
            android:textColorHint="@color/textColorHint"
            android:hint="@string/hint_player_two"
            android:textSize="@dimen/player_name_text_size"
            android:imeOptions="actionDone"
            android:textColor="@color/text_color"
            android:layout_width="match_parent"
            android:layout_weight="1"
            android:layout_height="0dp"/>


        <EditText
            android:id="@+id/player_three_id"
            android:textColorHint="@color/textColorHint"
            android:hint="@string/hint_player_three"
            android:textSize="@dimen/player_name_text_size"
            android:imeOptions="actionDone"
            android:textColor="@color/text_color"
            android:layout_width="match_parent"
            android:layout_weight="1"
            android:layout_height="0dp"/>


        <EditText
            android:id="@+id/player_four_id"
            android:textColorHint="@color/textColorHint"
            android:hint="@string/hint_player_four"
            android:textSize="@dimen/player_name_text_size"
            android:imeOptions="actionDone"
            android:textColor="@color/text_color"
            android:layout_width="match_parent"
            android:layout_weight="1"
            android:layout_height="0dp"/>




        <TextView
            android:layout_marginTop="@dimen/margin_choose_game_type"
            android:text="@string/switch_game_type"
            android:textColor="@color/text_color"
            android:textSize="@dimen/text_view_size"
            android:layout_width="wrap_content"
            android:layout_weight="0.5"
            android:layout_height="0dp"/>


        <Spinner
            android:id="@+id/spinner_game_mode_id"
            android:layout_marginTop="@dimen/spinner_margin_top_size"
            android:elevation="1dp"
            android:spinnerMode="dropdown"
            android:background="@drawable/spinner_style"
            android:layout_width="match_parent"
            android:textColor="@color/green_text"
            android:layout_weight="1"
            android:layout_height="0dp"/>


        <TextView
            android:textSize="@dimen/text_view_size"
            android:layout_marginTop="@dimen/margin_choose_game_type"
            android:layout_width="wrap_content"
            android:layout_weight="0.5"
            android:layout_height="0dp"
            android:text="@string/switch_airchiet_xishti"/>

        <Spinner
            android:id="@+id/spinner_xishti_id"
            android:layout_marginTop="@dimen/spinner_margin_top_size"
            android:elevation="1dp"
            android:background="@drawable/spinner_style"
            android:layout_width="match_parent"
            android:layout_weight="1"
            android:layout_height="0dp"/>


        <Switch
            android:layout_marginTop="@dimen/switch_margin_size"
            android:id="@+id/wyvilebi_switch_id"
            android:text="@string/pears"
            android:textSize="@dimen/switch_text_size"
            android:textColor="@color/text_color"
            android:layout_width="match_parent"
            android:layout_weight="0.5"
            android:layout_height="0dp"/>


        <Switch
            android:layout_marginTop="@dimen/switch_margin_size"
            android:id="@+id/moshla_switch_id"
            android:text="@string/moshla_switch_string"
            android:textSize="@dimen/switch_text_size"
            android:layout_width="match_parent"
            android:textColor="@color/text_color"
            android:layout_weight="0.5"
            android:layout_height="0dp"/>



        <Button
            android:layout_marginTop="@dimen/start_btn_margin_top_size"
            android:id="@+id/start_game_button_id"
            android:text="@string/start_game_button"
           android:layout_marginBottom="@dimen/start_btn_margin_bottom_size"
            android:textColor="@color/white"
            android:textSize="@dimen/start_game_btn_txt_size"
            android:background="@drawable/start_button_style"
            android:layout_width="match_parent"
            android:layout_weight="1"
            android:layout_height="0dp"/>


    </LinearLayout>


    </LinearLayout>


Solution

  • I solved this

    here is my xml

    ................
    <!-- Toolbar -->
    <include
        layout="@layout/toolbar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
    
    <!-- content-->
    
    <LinearLayout
        android:layout_below="@+id/toolbar"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:id="@+id/container">
    
        <!-- menu -->
        <LinearLayout
            android:layout_marginTop="@dimen/menu_margin_top"
            android:visibility="invisible"
            android:id="@+id/menu_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
    
        </LinearLayout>
    
    <!-- main container layout -->
    <LinearLayout
        android:id="@+id/main_container_id"
        android:orientation="vertical"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp">
    
        <!-- content container layout-->
    
        <LinearLayout
            android:orientation="vertical"
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="0dp">
    
    
        </LinearLayout>
    
    
        </LinearLayout>
    
    </LinearLayout>
    

    and here is java code

    private boolean isShown = false;
    private void burgerMenuIconClick(){
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!isShown) {
                    menuLayout.setVisibility(View.VISIBLE);
                    menuLayout.animate().translationY(menuLayout.getHeight());
                    isShown = true;
                } else {
                    menuLayout.animate().translationY(menuLayout.getHeight() * (-1));
                    isShown = false;
                }
            }
        });
    }