0

I have a NavigationView which has 4 buttons but I can't click them. I've made this metod of what to do when any of those buttons gets clicked but it doesn't work.

private DrawerLayout aDrawerLayout;
private ActionBarDrawerToggle aToggle;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pagina_inicial);

    //creating the dropdown menu
    aDrawerLayout = findViewById(R.id.dropdown_menu);
    aToggle = new ActionBarDrawerToggle(this, aDrawerLayout, R.string.abrir, R.string.fechar);
    aDrawerLayout.addDrawerListener(aToggle);
    aToggle.syncState();
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    //associating the listener to the navigation menu
    NavigationView navView = findViewById(R.id.menu_cair);
    navView.setNavigationItemSelectedListener(this);


    BottomNavigationView navigationView = (BottomNavigationView) findViewById(R.id.navigationView);

}
//what to do when one of the options gets clicked
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
    switch (item.getItemId()) {
        case R.id.paginaPerfil: {
            Toast.makeText(getApplicationContext(), "Perfil", Toast.LENGTH_LONG).show();
            break;
        }
        case R.id.paginaAjuda:{
            Toast.makeText(getApplicationContext(), "Ajuda", Toast.LENGTH_LONG).show();
            break;
        }
    }
    return true;
}}

I've already tried putting this metod inside of the onCreate but it didn't had any changes.

Also I have this navigationView values

<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".PaginaInicial"
android:background="#717171"
android:id="@+id/dropdown_menu">

<com.google.android.material.navigation.NavigationView
    android:id="@+id/menu_cair"
    app:menu="@menu/menu_navegacao"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@color/cinzentoClaro"
    app:itemTextColor="@color/azulEscuro"
    app:itemIconTint="@color/azulEscuro"
    />

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/navigationView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@color/cinzentoEscuro"
        android:outlineSpotShadowColor="@color/azulClaro"
        app:itemBackground="@color/azulClaro"
        app:itemIconTint="@animator/selector"
        app:itemTextColor="#ffffff"
        app:menu="@menu/menu_navegacao_baixo"/>
</RelativeLayout>

</androidx.drawerlayout.widget.DrawerLayout>

Here is most of the code where the error might be.

0 Answers0