Guest User

Untitled

a guest
Sep 20th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. <menu xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:app="http://schemas.android.com/apk/res-auto">
  3.  
  4. <group android:checkableBehavior="single">
  5. <item
  6. android:id="@+id/nav_camera"
  7. android:icon="@drawable/ic_menu_camera"
  8. android:title="Import" />
  9. <item
  10. android:id="@+id/nav_gallery"
  11. app:actionViewClass="android.widget.TextView"
  12. android:icon="@drawable/ic_menu_gallery"
  13. android:title="Gallery" />
  14. <item
  15. android:id="@+id/nav_slideshow"
  16. app:actionViewClass="android.widget.TextView"
  17. android:icon="@drawable/ic_menu_slideshow"
  18. android:title="Slideshow" />
  19. <item
  20. android:id="@+id/nav_manage"
  21. android:icon="@drawable/ic_menu_manage"
  22. android:title="Tools" />
  23. </group>
  24.  
  25. //Create these objects above OnCreate()of your main activity
  26. TextView slideshow,gallery;
  27.  
  28. //These lines should be added in the OnCreate() of your main activity
  29. gallery=(TextView) MenuItemCompat.getActionView(navigationView.getMenu().findItem(R.id.nav_gallery));
  30. slideshow=(TextView) MenuItemCompat.getActionView(navigationView.getMenu().findItem(R.id.nav_slideshow));
  31.  
  32. //This method will initialize the count value
  33. initializeCountDrawer();
  34.  
  35. private void initializeCountDrawer() {
  36. //Gravity property aligns the text
  37. gallery.setGravity(Gravity.CENTER_VERTICAL);
  38. gallery.setTypeface(null, Typeface.BOLD);
  39. gallery.setTextColor(getResources().getColor(R.color.colorAccent));
  40. gallery.setText("99+");
  41. slideshow.setGravity(Gravity.CENTER_VERTICAL);
  42. slideshow.setTypeface(null,Typeface.BOLD);
  43. slideshow.setTextColor(getResources().getColor(R.color.colorAccent));
  44.  
  45. //count is added
  46. slideshow.setText("7");
  47. }
  48.  
  49. NavigationView navigation = (NavigationView)findViewById(R.id.navigation);
  50. Menu menuNav = navigation.getMenu();
  51. MenuItem element = menuNav.findItem(R.id.item5);
  52. String before = element.getTitle().toString();
  53.  
  54. String counter = Integer.toString(5);
  55. String s = before + " "+counter+" ";
  56. SpannableString sColored = new SpannableString( s );
  57.  
  58. sColored.setSpan(new BackgroundColorSpan( Color.GRAY ), s.length()-3, s.length(), 0);
  59. sColored.setSpan(new ForegroundColorSpan( Color.WHITE ), s.length()-3, s.length(), 0);
  60.  
  61.  
  62. element.setTitle(sColored);
Add Comment
Please, Sign In to add comment