我以编程方式添加了一个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);

发布于 2018-03-06 06:43:13
由于视图是添加到coordinatorLayout中的,所以应该为BottomNavigationView添加CoordinatorLayoutParams。
CoordinatorLayout.LayoutParams layoutParams = new CoordinatorLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.gravity = Gravity.BOTTOM;
bottomNavigationView.setLayoutParams(layoutParams);https://stackoverflow.com/questions/49124780
复制相似问题