I'm trying to set onclicklistener on navigation railview but it doesn't work for me
Java code
binding.navigationRail.getHeaderView().setClickable(true);
binding.navigationRail.getHeaderView().setOnClickListener(v -> {
Toast.makeText(this, "headerview", Toast.LENGTH_SHORT).show();
});
Xml
<com.google.android.material.navigationrail.NavigationRailView
android:id="@ id/navigation_rail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:headerLayout="@layout/floatbutton_add_product"
app:menu="@menu/navigation_rail_menu" />
CodePudding user response:
that's worked for me
View header=binding.navigationRail.getHeaderView();
FloatingActionButton FloatingActionButton= header.findViewById(R.id.nav_rail_fab);
FloatingActionButton.setOnClickListener(v -> {
Toast.makeText(MainActivity.this, "headerview", Toast.LENGTH_SHORT).show();
});