0

I implemented the BottomBar from this library https://github.com/Droppers/AnimatedBottomBar

I created the tabs XML which is

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/tab_home"
        android:icon="@drawable/ic_action_home"
        android:title="@string/Home" />
    <item
        android:id="@+id/tab_publish"
        android:icon="@drawable/ic_action_publish"
        android:title="@string/Publish" />
    <item
        android:id="@+id/tab_map"
        android:icon="@drawable/ic_action_map"
        android:title="@string/Map" />
    <item
        android:id="@+id/tab_profile"
        android:icon="@drawable/ic_action_profile"
        android:title="@string/Profile" />
</menu>

and have it in my activity's XML as

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="wrap_content"
    android:layout_height="wrap_content"
   >

    <androidx.fragment.app.FragmentContainerView
        android:id="@+id/fragmentContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/bottom_bar"></androidx.fragment.app.FragmentContainerView>

    <nl.joery.animatedbottombar.AnimatedBottomBar
        android:id="@+id/bottom_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentBottom="true"
        android:background="@color/button_black"
        app:abb_indicatorColor="@color/instagramPink"
        app:abb_indicatorAppearance="round"
        app:abb_indicatorHeight="4dp"
        app:abb_indicatorMargin="16dp"
        app:abb_selectedIndex="1"
        app:abb_selectedTabType="text"
        app:abb_tabs="@menu/tabs"
        app:abb_badgeTextColor="@color/instagramPink"
        app:abb_tabColor="@color/instagramPink"
        app:abb_tabColorSelected="@color/white"
        />
</RelativeLayout>

Then the code for my activity is

public class MainActivity extends AppCompatActivity {

    private ActivityMainBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        final FragmentManager fragmentManager = getSupportFragmentManager();

        final Fragment fragment1 = new HomeFeed();
        final Fragment fragment2 = new CreateEvent();
        final MapsActivity fragment3 = new MapsActivity();
        final Fragment fragment4 = new ProfileActivity();

        binding.bottomBar.setOnTabSelectListener(item -> {
            Fragment fragment;
            switch (item.getItemId()) { //Error saying there is such no method as "getItemId"
                case R.id.tab_home:
                    fragment = fragment1;
                    break;
                case R.id.tab_publish:
                    fragment = fragment2;
                    break;
                case R.id.tab_map:
                    fragment = fragment3;
                    break;
                case R.id.tab_profile:
                default:
                    Fragment = fragment4;
                    break;
            }
            fragmentManager.beginTransaction().replace(R.id.fragmentContainer, fragment).commit();
            return true;
        });

        binding.bottomBar.setSelectedItemId(R.id.tab_home); //Error saying there is such no method as "setSelectedItemId"
    }
}

However, those two commented lines are giving me an error saying the methods do not exist. This is how I normally do it with my navigation bars, but I can't seem to find the way of setting it up for this particular one despite going over the docs. Please help!

Thank you

nkgtech
  • 3
  • 3

1 Answers1

0

Try this:

    public class MainActivity extends AppCompatActivity {

    private ActivityMainBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        final FragmentManager fragmentManager = getSupportFragmentManager();

        final Fragment fragment1 = new HomeFeed();
        final Fragment fragment2 = new CreateEvent();
        final MapsActivity fragment3 = new MapsActivity();
        final Fragment fragment4 = new ProfileActivity();

        binding.bottomBar.setOnTabSelectListener(item -> {
            Fragment fragment;
//REPLACEMENT
            switch (item.id) { //Error saying there is such no method as "getItemId"
                case R.id.tab_home:
                    fragment = fragment1;
                    break;
                case R.id.tab_publish:
                    fragment = fragment2;
                    break;
                case R.id.tab_map:
                    fragment = fragment3;
                    break;
                case R.id.tab_profile:
                default:
                    Fragment = fragment4;
                    break;
            }
            fragmentManager.beginTransaction().replace(R.id.fragmentContainer, fragment).commit();
            return true;
        });
//REPLACEMENT
        binding.bottomBar.selectTabById(R.id.tab_home); //Error saying there is such no method as "setSelectedItemId"
    }
}
Matt Grier
  • 206
  • 2
  • 9