Поскольку я использовал оба BottomNavigationView и NavigationDrawer в моем приложении, но возникает проблема, когда я помещаю кнопку Home в них обоих (BottomNavigationView и NavigationDrawer), кнопка для Navigation Drawer работает хорошо, но при использовании Home (Dashboard) из BottomNavigationView есть проблема возникает, когда я щелкаю по любой из карт, просматриваю cardView после выбора Home из BottomNavigationView, затем приложение падает, но работает хорошо, когда я открываю его из NavigationDrawer.
Вот ошибка:
java .lang.IllegalArgumentException: место назначения навигации com.appsnipp.admin: id / action_nav_home_to_nav_resource неизвестно этому NavController
Изображения приложения
Просмотр из дома из BottomNavigationView BottomNavigationView
Ящик навигации Ящик навигации Вот мои коды !!
Файл навигации
<?xml version="1.0" encoding="utf-8"?>
<navigation 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/mobile_navigation"
app:startDestination="@id/nav_home">
<fragment
android:id="@+id/nav_home"
android:name="com.appsnipp.admin.Navigation_Profile.ui.dashboard.DashBoardFragment"
android:label="@string/menu_home"
tools:layout="@layout/fragment_dashboard" >
<action
android:id="@+id/action_nav_home_to_nav_account2"
app:destination="@id/nav_account" />
<action
android:id="@+id/action_nav_home_to_navB_building2"
app:destination="@id/navB_building" />
<action
android:id="@+id/action_nav_home_to_navB_notice3"
app:destination="@id/navB_notice" />
<action
android:id="@+id/action_nav_home_to_nav_resource"
app:destination="@id/nav_resource" />
<action
android:id="@+id/action_nav_home_to_nav_complain"
app:destination="@id/nav_complain" />
<action
android:id="@+id/action_nav_home_to_navB_profile"
app:destination="@id/navB_profile" />
<action
android:id="@+id/action_nav_home_to_nav_visitor"
app:destination="@id/nav_visitor" />
<action
android:id="@+id/action_nav_home_to_nav_election"
app:destination="@id/nav_election" />
<action
android:id="@+id/action_nav_home_to_nav_document"
app:destination="@id/nav_document" />
<action
android:id="@+id/action_nav_home_to_nav_event"
app:destination="@id/nav_event" />
<action
android:id="@+id/action_nav_home_to_nav_member"
app:destination="@id/nav_member" />
</fragment>
<fragment
android:id="@+id/navB_home"
android:name="com.appsnipp.admin.Navigation_Profile.ui.dashboard.DashBoardFragment"
android:label="@string/menu_home"
tools:layout="@layout/fragment_dashboard" />
<fragment
android:id="@+id/navB_building"
android:name="com.appsnipp.admin.Navigation_Profile.ui.buildingdetails.BuildingDetailsFragment"
android:label="@string/menu_buiding"
tools:layout="@layout/fragment_buildingdetails" />
<fragment
android:id="@+id/navB_notice"
android:name="com.appsnipp.admin.Navigation_Profile.ui.noticeboard.NoticeBoardFragment"
android:label="@string/menu_notice"
tools:layout="@layout/fragment_notice" />
<fragment
android:id="@+id/navB_profile"
android:name="com.appsnipp.admin.Navigation_Profile.ui.profile.ProfileFragment"
android:label="Profile"
tools:layout="@layout/fragment_profile" />
<fragment
android:id="@+id/nav_account"
android:name="com.appsnipp.admin.Navigation_Profile.ui.account.AccountFragment"
android:label="@string/menu_account"
tools:layout="@layout/fragment_account" />
<fragment
android:id="@+id/nav_member"
android:name="com.appsnipp.admin.Navigation_Profile.ui.members.MembersFragment"
android:label="@string/menu_member"
tools:layout="@layout/fragment_member" />
<fragment
android:id="@+id/nav_election"
android:name="com.appsnipp.admin.Navigation_Profile.ui.electionandpoll.ElectionFragment"
android:label="@string/menu_election"
tools:layout="@layout/fragment_election" />
<fragment
android:id="@+id/nav_document"
android:name="com.appsnipp.admin.Navigation_Profile.ui.document.DocumentFragment"
android:label="@string/menu_document"
tools:layout="@layout/fragment_document" />
<fragment
android:id="@+id/nav_resource"
android:name="com.appsnipp.admin.Navigation_Profile.ui.resource.ResourceFragment"
android:label="@string/menu_resource"
tools:layout="@layout/fragment_resources" />
<fragment
android:id="@+id/nav_visitor"
android:name="com.appsnipp.admin.Navigation_Profile.ui.visitor.VisitorFragment"
android:label="@string/menu_visitor"
tools:layout="@layout/fragment_visitor" />
<fragment
android:id="@+id/nav_event"
android:name="com.appsnipp.admin.Navigation_Profile.ui.event.EventFragment"
android:label="@string/menu_event"
tools:layout="@layout/fragment_event" />
<fragment
android:id="@+id/nav_complain"
android:name="com.appsnipp.admin.Navigation_Profile.ui.complain.ComplainFragment"
android:label="@string/menu_complain"
tools:layout="@layout/fragment_complain" />
</navigation>
Файл BottomNavigationMenu
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/navB_home"
android:icon="@drawable/ic_home_black_24dp"
android:title="Home" />
<item
android:id="@+id/navB_building"
android:icon="@drawable/icon_building_black"
android:title="Building Details" />
<item
android:id="@+id/navB_notice"
android:icon="@drawable/icon_notice_black"
android:title="NoticeBoard" />
<item
android:id="@+id/navB_profile"
android:icon="@drawable/ic_person_outline_black_24dp"
android:title="Profile" />
</menu>
NavigationDrawer men u file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_home"
android:icon="@drawable/icon_home"
android:title="@string/menu_home"
/>
<item
android:id="@+id/nav_account"
android:icon="@drawable/icon_account"
android:title="@string/menu_account" />
<item
android:id="@+id/nav_member"
android:icon="@drawable/icon_member"
android:title="@string/menu_member" />
<item
android:id="@+id/nav_election"
android:icon="@drawable/icon_election"
android:title="@string/menu_election" />
<item
android:id="@+id/nav_document"
android:icon="@drawable/icon_document"
android:title="@string/menu_document" />
<item
android:id="@+id/nav_resource"
android:icon="@drawable/icon_resource"
android:title="@string/menu_resource" />
<item
android:id="@+id/nav_visitor"
android:icon="@drawable/icon_visitor"
android:title="@string/menu_visitor" />
<item
android:id="@+id/nav_event"
android:icon="@drawable/icon_event"
android:title="@string/menu_event" />
<item
android:id="@+id/nav_complain"
android:icon="@drawable/icon_complain"
android:title="@string/menu_complain" />
</group>
</menu>
NavigationDrawer. Активность кода для BottomNavigationView и NavigationDrawer выполняется здесь
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_navigation_);
...
DrawerLayout drawer = findViewById(R.id.drawer_layout);
navigationView =findViewById(R.id.nav_view);
bottomNavigationView = findViewById(R.id.nav_view_bottom);
CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) bottomNavigationView.getLayoutParams();
layoutParams.setBehavior(new BottomNavigationBehaviour());
bottomNavigationView.setSelectedItemId(R.id.navB_home);
navigationView=findViewById(R.id.nav_view);
navigationView.setCheckedItem(R.id.nav_home);
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
mAppBarConfiguration = new AppBarConfiguration.Builder(
R.id.nav_home, R.id.nav_account, R.id.nav_member,
R.id.nav_election, R.id.nav_document, R.id.nav_resource,R.id.navB_home,
R.id.nav_complain,R.id.navB_notice,
R.id.navB_building,R.id.navB_profile,
R.id.nav_event,R.id.nav_visitor)
.setDrawerLayout(drawer)
.build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
NavigationUI.setupWithNavController(bottomNavigationView,navController);
NavigationUI.setupWithNavController(navigationView, navController);
}
Файл HomeFragment
public class DashBoardFragment extends Fragment {
CardView c1,c2,c3,c4,c5,c6,c7,c8;
FragmentManager manager;
NavigationView navigationView;
private DashBoardViewModel dashBoardViewModel;
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
dashBoardViewModel =
ViewModelProviders.of(this).get(DashBoardViewModel.class);
View root = inflater.inflate(R.layout.fragment_dashboard, container, false);
navigationView =root.findViewById(R.id.nav_view);
manager=getFragmentManager();
c1=(CardView) root.findViewById(R.id.card_account);
c2=(CardView) root.findViewById(R.id.card_resource);
c3=(CardView) root.findViewById(R.id.card_document);
c4=(CardView) root.findViewById(R.id.card_member);
c5=(CardView) root.findViewById(R.id.card_event);
c6=(CardView) root.findViewById(R.id.card_election);
c7=(CardView) root.findViewById(R.id.card_complain);
c8=(CardView) root.findViewById(R.id.card_visitor);
c1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Navigation.findNavController(getActivity(), R.id.nav_host_fragment).navigate(R.id.action_nav_home_to_nav_account2);
}
});
c2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Navigation.findNavController(getActivity(), R.id.nav_host_fragment).navigate(R.id.action_nav_home_to_nav_resource);
}
});
c3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Navigation.findNavController(getActivity(), R.id.nav_host_fragment).navigate(R.id.action_nav_home_to_nav_document);
}
});
c4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Navigation.findNavController(getActivity(), R.id.nav_host_fragment).navigate(R.id.action_nav_home_to_nav_member);
}
});
c5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Navigation.findNavController(getActivity(), R.id.nav_host_fragment).navigate(R.id.action_nav_home_to_nav_event);
}
});
c6.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Navigation.findNavController(getActivity(), R.id.nav_host_fragment).navigate(R.id.action_nav_home_to_nav_election);
}
});
c7.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Navigation.findNavController(getActivity(), R.id.nav_host_fragment).navigate(R.id.action_nav_home_to_nav_complain);
}
});
c8.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Navigation.findNavController(getActivity(), R.id.nav_host_fragment).navigate(R.id.action_nav_home_to_nav_visitor);
}
});
return root;
}
}
, дайте мне знать, если какой-либо другой код файла
Заранее спасибо!