-1

I have researched on setting the navigation menu on Android. I have found a couple of answers on how to set it but my problem is that it is not even visible, sorry if this question is straight forward but am really new in this programming language, kindly help.

Here is my code:

activity_main.xml file:

enter code here

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.mywindows.neo_datawaysconsultantsandtrainers.MainActivity">


    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        android:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_height="match_parent"
        android:layout_width="match_parent">





        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello World!" />

        <ListView
            android:id="@+id/drawer"
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:background="@android:color/white"   />

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


</LinearLayout>

strings.xml file:

<resources>
    <string name="app_name">NEO-DATAWAYS</string>
    <string name="drawer_opened">Select an item</string>
    <string name="drawer_closed">NEODATAWAYS</string>
</resources>

styles.xml file:

enter code here

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">#006400</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:textColorPrimary">#FFFFFF</item>
        <item name="android:textColorSecondary">#FFFFFF</item>
    </style>

</resources>

activity_main.java file:

enter code here

package com.example.mywindows.neo_datawaysconsultantsandtrainers;

import android.content.res.Configuration;
import android.os.PersistableBundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;

public class MainActivity extends AppCompatActivity {


    private DrawerLayout mDrawLayout;
    private ActionBarDrawerToggle mDrawerToggle;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Toolbar toolbar=(Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);


        mDrawLayout=(DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerToggle=new ActionBarDrawerToggle(this,mDrawLayout,R.string.drawer_opened,R.string.drawer_closed){
            @Override
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
                if(getSupportActionBar()!=null)
                getSupportActionBar().setTitle(R.string.drawer_opened);
            }

            @Override
            public void onDrawerClosed(View drawerView) {
                super.onDrawerClosed(drawerView);
                if(getSupportActionBar()!=null)
                    getSupportActionBar().setTitle(R.string.drawer_closed);
            }
        };
        getSupportActionBar().setDisplayShowCustomEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);

        mDrawLayout.addDrawerListener(mDrawerToggle);
     //  mDrawLayout.setDrawerListener(mDrawerToggle);

    }

    @Override
    public void onPostCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
        super.onPostCreate(savedInstanceState, persistentState);
        mDrawerToggle.syncState();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        mDrawerToggle.onConfigurationChanged(newConfig);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        if(mDrawerToggle.onOptionsItemSelected(item))
            return true;


        return super.onOptionsItemSelected(item);

    }
}
eightShirt
  • 1,457
  • 2
  • 15
  • 29
ipitah
  • 15
  • 1
    Try defining onCreateOptionMenu and make a menu.xml file where you have to include the things that you need to show in navigation menu – Swr7der Nov 18 '16 at 07:13

1 Answers1

0

[activity_main.xml]

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

<ListView android:layout_width="240dp"
    android:layout_height="match_parent"
    android:id="@+id/lv_activity_main_nav_list"
    android:layout_gravity="start"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp"
    android:background="#EDEDED"/>

more code this url - http://androidhuman.com/524