I am trying to implement a navigation drawer in all of my activities (NOTE: NOT FRAGMENT). I did so and I even initialize onNavigationItemSelected but my menu are still not clickable. As in, the navigation drawer does indeed slide right but the menu options are not clickable and does not go to the next activity.
I have two types of menu - one is the navigation drawer on the top right and another is the ellipsis type on the top left. My top left is working fine but not the navigation drawer.
Below are my codes for navigation drawer:
at OnCreate:
nv = findViewById(R.id.nvNavView);
nv.setNavigationItemSelectedListener(this);
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
int id = menuItem.getItemId();
switch (id){
case R.id.navKnowledge:{
Intent intent = new Intent(SecondActivity.this, KnowledgeActivity.class);
startActivity(intent);
break;
}
case R.id.navRules:{
Intent intent = new Intent(SecondActivity.this, RulesActivity.class);
startActivity(intent);
break;
}
}
return true;
}
onCreateOptions:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
// getMenuInflater().inflate(R.menu.navigation_menu,
menu);
return true;
}
drawer layout XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.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=".SecondActivity"
android:orientation="vertical"
android:gravity="center"
android:background="#f9f0e1"
android:id="@+id/drawerLayout">
<android.support.design.widget.NavigationView
android:id="@+id/nvNavView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:menu="@menu/navigation_menu"
android:layout_gravity="start">
</android.support.design.widget.NavigationView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:clipToPadding="false"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.CardView
android:id="@+id/btnSecondtoKnowledge"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
app:cardElevation="10dp"
android:background="@drawable/circlebgpurple">
<LinearLayout
android:layout_width="130dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:background="@drawable/circlebgpurple">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:background="@drawable/circlewhite"
android:src="@drawable/ic_knowledge"
android:padding="10dp"
android:layout_marginTop="5dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:text="Knowledge"
android:textColor="#000000"/>
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="#3a00a4"
android:layout_margin="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Search Knowledge"
android:textStyle="bold"
android:padding="1dp"
android:textColor="#000000"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/btnSecondtoRules"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
app:cardElevation="10dp">
<LinearLayout
android:layout_width="130dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:background="@drawable/circlebgpink"
>
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:background="@drawable/circlewhite"
android:src="@drawable/ic_rules"
android:padding="10dp"
android:layout_marginTop="5dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:text="Business Rules"
android:textColor="#000000"/>
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="#ed9bd5"
android:layout_margin="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Search Biz. Rules"
android:textStyle="bold"
android:padding="1dp"
android:textColor="#000000"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<LinearLayout
android:clipToPadding="false"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.CardView
android:id="@+id/btnSecondtoFaq"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
app:cardElevation="10dp">
<LinearLayout
android:layout_width="130dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:background="@drawable/circlebgyellow"
>
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:background="@drawable/circlewhite"
android:src="@drawable/ic_faq"
android:padding="10dp"
android:layout_marginTop="5dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:text="FAQ"
android:textColor="#000000"/>
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="#fbff00"
android:layout_margin="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Clear Doubts Here"
android:textStyle="bold"
android:padding="1dp"
android:textColor="#000000"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/btnSecondtoQuery"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
app:cardElevation="10dp">
<LinearLayout
android:layout_width="130dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:background="@drawable/circlebggreen"
>
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:background="@drawable/circlewhite"
android:src="@drawable/ic_query"
android:padding="10dp"
android:layout_marginTop="5dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:text="Query"
android:textColor="#000000"/>
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="#00a700"
android:layout_margin="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Submit New Query"
android:textStyle="bold"
android:padding="1dp"
android:textColor="#000000"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<LinearLayout
android:clipToPadding="false"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.CardView
android:id="@+id/btnSecondtoProfile"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
app:cardElevation="10dp">
<LinearLayout
android:layout_width="130dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:background="@drawable/circlebglightpink"
>
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:background="@drawable/circlewhite"
android:src="@drawable/ic_profile"
android:padding="10dp"
android:layout_marginTop="5dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:text="Profile"
android:textColor="#000000"/>
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="#004ba7"
android:layout_margin="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="My Personal Details"
android:textStyle="bold"
android:padding="1dp"
android:textColor="#000000"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/btnSecondtoHelp"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
app:cardElevation="10dp">
<LinearLayout
android:layout_width="130dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:background="@drawable/circlebgorange"
>
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:background="@drawable/circlewhite"
android:src="@drawable/ic_help"
android:padding="10dp"
android:layout_marginTop="5dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:text="Help"
android:textColor="#000000"/>
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="#f29d60"
android:layout_margin="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Help & Information"
android:textStyle="bold"
android:padding="1dp"
android:textColor="#000000"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout>
navigation menu xml
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single"/>
<item android:id="@+id/navKnowledge"
android:title="Search Knowledge"
android:icon="@drawable/ic_knowledge"/>
<item android:id="@+id/navRules"
android:title="Search Biz. Rules"
android:icon="@drawable/ic_rules"/>
<item android:id="@+id/navFaq"
android:title="FAQ"
android:icon="@drawable/ic_faq"/>
<item android:id="@+id/navQuery"
android:title="Submit New Query"
android:icon="@drawable/ic_query"/>
<item android:id="@+id/navProfile"
android:title="My Account"
android:icon="@drawable/ic_profile"/>
<item android:id="@+id/navHelp"
android:title="Help & Navigation"
android:icon="@drawable/ic_help"/>
I commented out the menu inflater for navigation drawer because although they are clickable, the menu appeared as the 3 dots on top left instead of where i wanted it to be (top right corner and the menu is the 3 lines type).
Does anyone know if I'm doing it wrong somewhere? Can guide me through?
Thanks.