I try to add a bottom navigation view dynamically. I know that I add a navigation view inside activity's xml file.
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
design:menu="@menu/items" />
I don't want to create a item xml file. I used below code to create navigation bar.
bottomNavigationView = new BottomNavigationView(this);
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
bottomNavigationView.setLayoutParams(params);
RelativeLayout layout = (RelativeLayout) findViewById(R.id.viewLayout);
layout.addView(bottomNavigationView);
Menu menu = bottomNavigationView.getMenu();
menu.add(0, i, Menu.NONE, "TEXT");
menu.add throws an error.
android.support.v7.view.menu.MenuBuilder.size()' on a null object reference
How can I add a navigation view dynamically?