横向模式下的底部导航材料设计

时间:2019-05-28 14:35:28

标签: android

我目前正在实施底部导航,我想遵循材料设计指南(https://material.io/design/components/bottom-navigation.html

在“景观”中,我想使“底部导航”看起来像这样: Design Guidline for Landscape

我找到了一个可行的编程解决方案:

public void setLandscapeStyle(Context context) {
    BottomNavigationView view = layout.findViewById(R.id.bottom_navigation);
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    BottomNavigationMenuView navigationMenuView = (BottomNavigationMenuView) view.getChildAt(0);
    Menu menu = view.getMenu();
    for (int i = 0; i < menu.size(); i++) {
        BottomNavigationItemView item = (BottomNavigationItemView) navigationMenuView.getChildAt(i);
        View itemBottomNavigation = inflater.inflate(R.layout.layout_bottom_navigation_item, navigationMenuView, false);
        ((ImageView) itemBottomNavigation.findViewById(R.id.icon)).setImageDrawable(menu.getItem(i).getIcon());
        ((TextView) itemBottomNavigation.findViewById(R.id.title)).setText(menu.getItem(i).getTitle());
        item.removeAllViews();
        item.addView(itemBottomNavigation);
    }
}

但是,如果我能避免使用此代码段并在xml中找到解决方案,那就太好了。我使用Bottomnavigation的menuItem的actionlayout尝试了xml中的解决方案,但发现Bottomnavigation不支持自定义项。

0 个答案:

没有答案