I am trying to display a navigation box on a toolbar. As I think, I already wrote everything that he needs, but nothing is displayed on the toolbar. Just a text zoo. No icon to display the navigation bar
I am new to android and it will not be a surprise for me if I missed something.
Here is my MainActivity.java
package com.example.zoo; import android.content.res.Configuration; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.View; import android.view.Menu; import android.view.MenuItem; public class MainActivity extends AppCompatActivity { private DrawerLayout mDrawerLayout; private ActionBarDrawerToggle mActionBarDrawerToggle; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_Layout); mActionBarDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, 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); } } }; mDrawerLayout.setDrawerListener(mActionBarDrawerToggle); } @Override protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); mActionBarDrawerToggle.syncState(); } @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); mActionBarDrawerToggle.onConfigurationChanged(newConfig); } @Override public boolean onCreateOptionsMenu(Menu menu) {
Here is my content_main.xml
<?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:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.gsiradze.zoo.MainActivity" android:orientation="vertical"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_height="wrap_content" android:layout_width="match_parent" android:background="?attr/colorPrimary" android:minHeight="?android:attr/actionBarSize"/> <android.support.v4.widget.DrawerLayout android:id="@+id/drawer_Layout" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/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>
and of course i have these line names
<resources> <string name="drawer_opened">Select an item</string> <string name="drawer_closed">Zoo</string> </resources>
source share