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:
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);
– viana
@acklay tried now and still not appearing.
– porthfind
@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.
– porthfind
Put your Toolbar XML in your question.
– viana
@acklay updated.
– porthfind
Below
Toolbar toolbar...
, placesetSupportActionBar(toolbar)
;– viana
@acklay already put. It looked the same.
– porthfind
I see nothing wrong.
– ramaral
You compiled and nothing?! In this XML you put here, I’m not seeing any Drawerlayout . Because?
– viana
@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" />
– porthfind
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
– viana
@acklay thanks, I’ll see.
– porthfind