I am developing an Android App. In my app, I am using navigation drawer and navigation view. But I set the menu item for them programmatically. For a menu item, I set both icon and title. But I am having a problem with that. That is I cannot set the spacing between icon and title that I programmatically added to menu.
This is how I programmatically add item to menu
Menu menu = leftDrawer.getMenu();
SubMenu subMenu = menu.addSubMenu(MAIN_MENU_ITEM_GROUP_ID, 99, 99, "Others");
subMenu.add(MAIN_MENU_ITEM_GROUP_ID,96,96,"Monthly Leaderboard").setIcon(R.drawable.leaderboard_icon).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
startActivity(new Intent(MainActivity.this, LeaderboardActivity.class));
return false;
}
});
subMenu.add(MAIN_MENU_ITEM_GROUP_ID,96,96,"Settings").setIcon(R.drawable.settings_icon).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
startActivity(new Intent(MainActivity.this, SettingsActivity.class));
return false;
}
});
But spacing between between icon and title is not properly set.
This is the screenshot of my problem
As you can see in screenshot, spacing between left side of screen and icon and spacing between icon and title are not same. How can I set the spacing between icon and title of menu item programmatically?