I can’t put hamburger symbol on Navigation Drawer Panel

Asked

Viewed 75 times

2

I’m trying to put one navigation Drawer Panel in my app, but I can’t put the burger symbol on my MainActivity. The code I’m using is:

public class MainActivity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.addDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);

This is what it looks like:

inserir a descrição da imagem aqui

Toolbar XML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@drawable/toolbar_main">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:textColor="@color/brown"
            android:textSize="26sp"
            android:textStyle="bold"
            android:text="@string/app_name2"
            android:gravity="center"
            android:id="@+id/toolbar_title"/>

    </android.support.v7.widget.Toolbar>

toolbar_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/white" />
        </shape>
    </item>
    <item android:bottom="2dp">
        <shape android:shape="rectangle">
            <gradient android:angle="-90" android:startColor="@color/amarelo1" android:endColor="@color/amarelo2"  />

        </shape>
    </item>
</layer-list>

I’ve tried to put toolbar.setNavigationIcon(R.drawable.ic_drawer); and it doesn’t work either. Someone can help?

  • Have you tried inserting the toggle.setDrawerIndicatorEnabled(true);

  • @acklay tried now and still not appearing.

  • @ramaral had already tried, but I still can’t. I put a small printscreen of what appears to me. The only solution I remember is to put an Imagebutton on the Toolbar, but it shouldn’t be necessary.

  • Put your Toolbar XML in your question.

  • @acklay updated.

  • Below Toolbar toolbar..., place setSupportActionBar(toolbar);

  • @acklay already put. It looked the same.

  • I see nothing wrong.

  • You compiled and nothing?! In this XML you put here, I’m not seeing any Drawerlayout . Because?

  • @acklay because Drawerlayout is in another xml, activity_main.xml where I have a include and call Toolbar XML q put here. <include layout="@layout/app_bar_main" android:layout_width="match_parent" android:layout_height="match_parent" />

  • Here with me appears the button normally using your code. Take a look at my project here and see if there’s anything you don’t have on your https://github.com/cleidimarviana/navDrawer/blob/master/app/src/main/java/comseamusdawkins/MainActivity.java

  • @acklay thanks, I’ll see.

Show 7 more comments

1 answer

0

Keep the instance of DrawerToggle and call the syncState() in onPostCreate

@Override
protected void onPostCreate(@Nullable Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);

    this.drawerToggle.syncState();
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.