使用預設的 DividerItemDecoration 新增選單分隔符

只需使用預設的 DividerItemDecoration 類:

NavigationView navigationView = (NavigationView) findViewById(R.id.navigation);
NavigationMenuView navMenuView = (NavigationMenuView) navigationView.getChildAt(0);
navMenuView.addItemDecoration(new DividerItemDecoration(context,DividerItemDecoration.VERTICAL));

預習 :

StackOverflow 文件