1
How do I make the Drawer layout buttons take me to another screen? I tried this way , but it didn’t work Another thing, when I click on the Drawer menu, it looks like it’s just a text, don’t give that click effect, I’ll leave my entire Mainactivity below
@SuppressWarnings("StatementWithEmptyBody")
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.testando) {
Button button = (Button) findViewById(R.id.testando);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent it= new Intent(MainActivity.this,
Ingredientes.class);
}
});
Mainactivity Inteiro
import android.content.Intent;
import android.support.v4.view.GravityCompat;
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;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Toolbar toolbar;
Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
toggle.syncState();
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@SuppressWarnings("StatementWithEmptyBody")
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.testando) {
Button button = (Button) findViewById(R.id.testando);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent it= new Intent(MainActivity.this, Ingredientes.class);
}
});
} else if (id == R.id.passo1) {
} else if (id == R.id.passo2) {
} else if (id == R.id.passo3) {
} else if (id == R.id.passo4) {
} else if (id == R.id.passo5) {
} else if (id == R.id.passo6) {
} else if (id == R.id.passo7) {
} else if (id == R.id.passo8) {
} else if (id == R.id.donate) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
Actually I rushed, but it was just a suggested navigation with Fragment. I will do this in the comments.
– viana
I know that your intention was to help, but just as the questions must be objective, the answers must also be so and you must answer the question. :)
– ramaral