我以编程方式添加了BottomNavigationView
,但它在工具栏上方,我该如何解决?
View parent = (View) container.getParent();
coordinatorLayout = parent.findViewById(R.id.parent_container);
bottomNavigationView = new BottomNavigationView(getContext());
BottomNavigationView.LayoutParams params = new BottomNavigationView.LayoutParams(BottomNavigationView.LayoutParams.MATCH_PARENT, BottomNavigationView.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM);
bottomNavigationView.setLayoutParams(params);
bottomNavigationView.setBackgroundColor(getResources().getColor(R.color.colorPrimaryDark));
bottomNavigationView.inflateMenu(R.menu.bottom_navigation_main);
coordinatorLayout.addView(bottomNavigationView, params);
答案 0 :(得分:-1)
由于视图已添加到coordinatorLayout,您应该为BottomNavigationView添加CoordinatorLayoutParams。
CoordinatorLayout.LayoutParams layoutParams = new CoordinatorLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.gravity = Gravity.BOTTOM;
bottomNavigationView.setLayoutParams(layoutParams);