-1
public class MainActivity extends AppCompatActivity {
private AppBarConfiguration mAppBarConfiguration;
ImageView imageView_Carrinho;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
imageView_Carrinho = findViewById(R.id.imageView_Carrinho);
imageView_Carrinho.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, CarrinhoAdapter.class);
startActivity(i);
}
});
// Cria referencia para toda a area do navigation drawer
DrawerLayout drawer = findViewById(R.id.drawer_layout);
//Cria referencia para a area de navegação
NavigationView navigationView = findViewById(R.id.nav_view);
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
NavigationView navigationView1 = findViewById(R.id.nav_sair);
//Define configurações do navigation drawer
mAppBarConfiguration = new AppBarConfiguration.Builder(
R.id.nav_home, R.id.nav_gallery, R.id.nav_slideshow)
.setDrawerLayout(drawer)
.build();
//Configura area que ira carregar os fragments
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
//Configura menu superior da navegação
NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
//Configura
NavigationUI.setupWithNavController(navigationView, navController);
navigationView.setNavigationItemSelectedListener
(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
switch (menuItem.getItemId())
{
case R.id.nav_sair:
//faça qualquer ação aqui
Intent intent = new Intent(MainActivity.this, LoginActivity.class);
finish();
startActivity(intent);
break;
}
return true;
}
});
}
/** @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}**/
@Override
public boolean onSupportNavigateUp() {
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
return NavigationUI.navigateUp(navController, mAppBarConfiguration)
|| super.onSupportNavigateUp();
}
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer"
android:background="@drawable/degrade_menu2"
app:itemTextColor="@color/Branco"
app:itemIconTint="@color/Branco"
/>
</androidx.drawerlayout.widget.DrawerLayout>```
Tell which part of the app each code refers to. In the title just enter the problem, leave to give the details in the question.
– Boneco Sinforoso
sorry, I’m new r
– Vinicius Mota