0

I have a menu resource file in my Android app which I want to appear on all screens in my application as a Bottom Navigation Bar.

    <item
        android:id="@+id/navigation_home"
        android:icon="@drawable/home_nav"
        android:title="@string/home"
        android:onClick="goHome"/>

    <item
        android:id="@+id/navigation_timer"
        android:icon="@drawable/timer_nav"
        android:title="@string/timer"
        android:onClick="goToTimer"/>

    <item
        android:id="@+id/navigation_myAlarms"
        android:icon="@drawable/myalarms_nav"
        android:title="@string/my_alarms"
        android:onClick="goToAlarms"
        />

    <item
        android:id="@+id/navigation_settings"
        android:icon="@drawable/settings_nav"
        android:title="@string/preferences"
        android:onClick="goSettings"
        />

In order to fire the new screens I have used the android:onClick attribute to link to some methods which I put in my MainActivity.

    public void goHome(MenuItem m) {
        Intent h = new Intent(this, MainActivity.class);
        startActivity(h);
    }

    public void goToTimer(MenuItem m) {
        Intent t = new Intent(this, TimerActivity.class);
        startActivity(t);
    }

    public void goToAlarms(MenuItem m) {
        Intent a = new Intent(this, MyAlarms.class);
        startActivity(a);
    }

    public void goSettings(MenuItem m) {
        Intent s = new Intent(this, SettingsActivity.class);
        startActivity(s);
    }

This works to navigate to the new screens, but it will crash if they have action bars too. I'm not sure why this is but I know I'm doing something wrong. Can anybody help? Thanks

  • 1
    please share the logcat – Usman Zafer Apr 06 '20 at 19:54
  • "but it will crash if they have action bars too" – How have you determined that having an `ActionBar` is the cause? Also, as Usman said, please [edit] your question to provide the complete [stack trace from the crash](https://stackoverflow.com/a/23353174). – Mike M. Apr 07 '20 at 00:48

0 Answers0