• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How to get Navigation drawer visible?

Hello there, I'm a beginner with app development and I was wondering what I need to do in order to get my Navigationdrawer visible on my main activity. I am using Android Studio. It shows when I preview it but when I actually run it in an emulator it is nowhere to be seen. So when I started this project I picked the Bottom menu activity layout and proceeded on to create the menus, then I went to resources---new---activity--navigation drawer. Below you can see all the content I have under "layout". I would like to have the navigation drawer visible on all pages. These are the settings I used when I added the new activity to my existing project.

901063f4696a4dcc9dfa085a25e87774.png



8368a9f8258a4444849c4e0f944b2296.png



When in preview mode I can see the navigation drawer like so:

8cecb951a4a041b0903b2a3f33a100aa.png



But when running on the emulator this is what I see:

b1a1dcc5bc2047d196b27b500fa96afd.png


I would highly appreciate if anyone could point me in the right direction, thank you for taking time out of your day to read this post, have a good day.
 
Hi. Welcome to Android Forums.
Can you show the code of your MainActivity please? use [code][/code] tags.
 
Hi. Welcome to Android Forums.
Can you show the code of your MainActivity please? use [code][/code] tags.

This is the mainactivity java file.
Code:
package com.example.fred.spotpal;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.widget.TextView;

public class Bottom_menu extends AppCompatActivity {

    private TextView mTextMessage;

    private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
            = new BottomNavigationView.OnNavigationItemSelectedListener() {

        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            switch (item.getItemId()) {

                case R.id.navigation_home:
                mTextMessage.setText(R.string.title_home);
                return true;

                case R.id.navigation_settings:
                    mTextMessage.setText("Settings");
                    return true;

                case R.id.navigation_distance:
                    mTextMessage.setText("Distance");
                    return true;

                case R.id.navigation_buddies:
                    mTextMessage.setText("Buddies");
                    return true;

                case R.id.navigation_inbox:
                    mTextMessage.setText("Inbox");
                    return true;
            }
            return false;
        }

    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bottom_menu);

        mTextMessage = (TextView) findViewById(R.id.message);
        BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
        navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
    }

}
[/plain]

This is the main activity's xml file

Code:
<FrameLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <TextView
            android:id="@+id/message"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/activity_vertical_margin"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginRight="@dimen/activity_horizontal_margin"
            android:layout_marginTop="@dimen/activity_vertical_margin"
            android:text="@string/title_home" />

    </FrameLayout>

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="?android:attr/windowBackground"
        app:menu="@menu/navigation" />

</LinearLayout>

This is the manifest file:

Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.fred.spotpal">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".Bottom_menu"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".NavigationDrawer"
            android:label="@string/title_activity_navigation_drawer"
            android:parentActivityName=".Bottom_menu"
            android:theme="@style/AppTheme.NoActionBar">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.example.fred.spotpal.Bottom_menu" />
        </activity>

    </application>

</manifest>
 
I think your code is incomplete. You need to set a ListView and adapter for the nav drawer items. Have a look at this article:

http://blog.teamtreehouse.com/add-navigation-drawer-android

It's visible in the layout preview because you are being shown a placeholder nav menu component.

Do I post the listview + adapter in the main java file? Does it matter where I post them in that file? I got a bit confused due to him having different layouts as I have no drawlayout that he is using for his example.
 
Back
Top Bottom