Android’s NavigationView simplifies creating navigation drawer menus, but it has a limitation: you can only add headers and menu items - no footer support.
Understanding the Internal Structure
NavigationView internally uses a ListView (specifically NavigationMenuView) to display menu items. Headers are added via ListView.addHeaderView().
The Solution
Since it’s a ListView under the hood, we can use ListView.addFooterView():
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
NavigationView navigationView = findViewById(R.id.nav_view);
// Get the internal ListView
NavigationMenuView navMenuView = (NavigationMenuView)
navigationView.getChildAt(0);
// Create and add footer
View footer = getLayoutInflater()
.inflate(R.layout.nav_footer, navMenuView, false);
navMenuView.addFooterView(footer);
}
}
Important Caveat
This worked in early versions of the Support Library, but Google later replaced ListView with RecyclerView in NavigationMenuView (around version 23.1.1+).
For newer versions, you’ll need a different approach:
- Use a custom NavigationView implementation
- Add the footer as the last menu item with custom styling
- Use a completely custom navigation drawer layout
When to Use This
This workaround is useful for older projects or when you have specific version constraints. For new projects, consider designing your navigation without relying on internal implementation details.